The Python 2 documentation says that \"programmers are encouraged to derive new exceptions from the Exception class or one of its subclasses, and not from BaseException\". Witho
Exceptions derived from BaseException
are: GeneratorExit
, KeyboardInterrupt
, SystemExit
.
According to the documentation:
So the usual reasons are to prevent try ... except Exception
accidently prevent interpreter exit (except GeneratorExit
)
UPDATE after seeing Ashwini Chaudhary's comment:
PEP 352 - Required Superclass for Exceptions explains the reason.
With the exception hierarchy now even more important since it has a basic root, a change to the existing hierarchy is called for. As it stands now, if one wants to catch all exceptions that signal an error and do not mean the interpreter should be allowed to exit, you must specify all but two exceptions specifically in an except clause or catch the two exceptions separately and then re-raise them and have all other exceptions fall through to a bare except clause:
except (KeyboardInterrupt, SystemExit): raise except: ...
That is needlessly explicit. This PEP proposes moving KeyboardInterrupt and SystemExit to inherit directly from BaseException.