Table 10.2 lists all of Python's current set of standard exceptions. All exceptions are loaded into the interpreter as a built-in so they are ready before your script starts or by the time you receive the interpreter prompt, if running interactively.
All standard/built-in exceptions are derived from the root class Exception. There are currently two immediate subclasses of Exception: SystemExit and StandardError. All other built-in exceptions are subclasses of StandardError. Every level of indentation of an exception listed in Table 10.2 indicates one level of exception class derivation.
Exception Name | Description |
---|---|
Exception[a] | root class for all exceptions |
SystemExit | request termination of Python interpreter |
StandardError[a] | base class for all standard built-in exceptions |
ArithmeticError[a] | base class for all numeric calculation errors |
FloatingPointError[a] | error in floating point calculation |
OverflowError | calculation exceeded maximum limit for numerical type |
ZeroDivisionError | division (or modulus) by zero error (all numeric types) |
AssertionError[a] | failure of assert statement |
AttributeError | no such object attribute |
EOFError | end-of-file marker reached without input from built-in |
EnvironmentError[b] | base class for operating system environment errors |
IOError | failure of input/output operation |
OSError[b] | operating system error |
WindowsError[c] | MS Windows system call failure |
ImportError | failure to import module or object |
KeyboardInterrupt | user interrupted execution (usually by typing ^C) |
LookupError[a] | base class for invalid data lookup errors |
IndexError | no such index in sequence |
KeyError | no such key in mapping |
MemoryError | out-of-memory error (non-fatal to Python interpreter) |
NameError | undeclared/uninitialized object (non-attribute) |
UnboundLocalError[c] | access of an uninitialized local variable |
RuntimeError | generic default error during execution |
NotImplementedError[b] | unimplemented method |
SyntaxError | error in Python syntax |
IndentationError[d] | improper indentation |
TableError[d] | improper mixture of TABs and spaces |
SystemError | generic interpreter system error |
TypeError | invalid operation for type |
ValueError | invalid argument given |
UnicodeError[c] | Unicode related error |
[a] Prior to Python 1.5, the exceptions denoted did not exist. All earlier exceptions were string-based.
[b] New as of Python 1.5.2
[c] New as of Python 1.6
[d] New as of Python 2.0