all Python 3Exceptionsexception
BaseException
built-in exceptions
The root of the exception hierarchy; catches everything, including SystemExit/KeyboardInterrupt.
Syntax
raise BaseException
What separates it from Exception is exactly the set of "stop the program" signals: SystemExit, KeyboardInterrupt and GeneratorExit inherit from BaseException directly. That is why except BaseException — and its twin, a bare except: — swallows Ctrl+C and sys.exit(), leaving the process unable to quit. If you do catch it for cleanup, end the handler with a bare raise.
Examples
try:
raise BaseException
except BaseException as e:
print(type(e).__name__) # → BaseException
See also
Open in the full glossarydocs.python.orgReport an inaccuracy