A variety of exceptions are built into Python, and they are arranged in a hierarchy so that you can handle either specific individual exceptions or larger groupings of them.
Here is the current exception hierarchy. Indentation
shows the inheritance: for example, all exceptions inherit
ArithmeticError inherits from
StandardError; and so on.
Exception: Base class for
Normal program termination. This exception is not
considered an error.
This is a special exception to be used with
iterators and generators; see
Base class for all exceptions that are considered errors.
Errors from numeric operations.
Failure in a floating point operation.
A numeric operation that led to a number
too large to be represented.
Attempt to divide by zero.
Trying to retrieve an element of a sequence
when the index is out of range.
Trying to retrieve an item from a mapping
that does not contain the given key.
Base class for external errors. For the
exceptions in this class, the associated
value is an object with the error number in its
.errno attribute and
the error message in its
Operating system error.
statement has failed.
Attempt to retrieve or set a nonexistent
attribute of an object.
Attempt to import a nonexistent module, or a
nonexistent name from a module.
Someone pressed interrupt (e.g., control-C
No more memory is available.
Reference to an undefined name.
Use this exception for functions that aren't
written yet. It's also recommended for virtual
methods in base classes, those intended to be
Attempt to import or execute syntactically
invalid Python source code.
An internal error in Python.
Attempt to use an operation that isn't defined
for objects of the type it's to operate
Attempt to operate on an inappropriate