10.8. Standard Exceptions

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.

Table 10.2. Python Standard Exceptions
Exception NameDescription
Exception[a]root class for all exceptions
SystemExitrequest 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
OverflowErrorcalculation exceeded maximum limit for numerical type
ZeroDivisionError division (or modulus) by zero error (all numeric types)
AssertionError[a]failure of assert statement
AttributeErrorno such object attribute
EOFErrorend-of-file marker reached without input from built-in
EnvironmentError[b]base class for operating system environment errors
IOErrorfailure of input/output operation
OSError[b] operating system error
WindowsError[c]MS Windows system call failure
ImportErrorfailure to import module or object
KeyboardInterrupt user interrupted execution (usually by typing ^C)
LookupError[a]base class for invalid data lookup errors
IndexErrorno such index in sequence
KeyErrorno such key in mapping
MemoryErrorout-of-memory error (non-fatal to Python interpreter)
NameErrorundeclared/uninitialized object (non-attribute)
UnboundLocalError[c]access of an uninitialized local variable
RuntimeErrorgeneric default error during execution
NotImplementedError[b]unimplemented method
SyntaxErrorerror 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

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset