The exceptions Module
The exceptions module provides the standard exception hierarchy. It’s
automatically imported when Python starts, and the exceptions are
added to the _ _builtin_ _ module. In
other words, you usually don’t need to import this module.
This is a Python module in 1.5.2, and a built-in module in 2.0 and later.
The following standard exceptions are defined by this module:
Exceptionis used as a base class for all exceptions. It’s strongly recommended (but not yet required) that user exceptions are derived from this class too.SystemExit(Exception)is raised by thesys.exitfunction. If it propagates to the top level without being caught by atry-exceptclause, the interpreter is terminated without a traceback message.StandardError(Exception)is used as a base class for all standard exceptions (exceptSystemExit, that is).KeyboardInterrupt(StandardError)is raised when the user presses Control-C (or any other interrupt key). Note that this may cause strange errors if you use “catch all”try-exceptstatements.ImportError(StandardError)is raised when Python fails to import a module.EnvironmentErroris used as a base class for exceptions that can be caused by the interpreter’s environment (that is, they’re usually not caused by bugs in the program).IOError(EnvironmentError)is used to flag I/O-related errors.OSError(EnvironmentError)is used to flag errors by theosmodule.WindowsError(OSError)is used to flag Windows-specific errors from the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access