4.1 Standard Exceptions
All standard Python exceptions are available as global variables whose
names are "PyExc_" followed by the Python exception name. These
have the type PyObject*; they are all class objects. For
completeness, here are all the variables:
C Name |
Python Name |
Notes |
PyExc_Exception |
Exception |
(1) |
PyExc_StandardError |
StandardError |
(1) |
PyExc_ArithmeticError |
ArithmeticError |
(1) |
PyExc_LookupError |
LookupError |
(1) |
PyExc_AssertionError |
AssertionError |
|
PyExc_AttributeError |
AttributeError |
|
PyExc_EOFError |
EOFError |
|
PyExc_EnvironmentError |
EnvironmentError |
(1) |
PyExc_FloatingPointError |
FloatingPointError |
|
PyExc_IOError |
IOError |
|
PyExc_ImportError |
ImportError |
|
PyExc_IndexError |
IndexError |
|
PyExc_KeyError |
KeyError |
|
PyExc_KeyboardInterrupt |
KeyboardInterrupt |
|
PyExc_MemoryError |
MemoryError |
|
PyExc_NameError |
NameError |
|
PyExc_NotImplementedError |
NotImplementedError |
|
PyExc_OSError |
OSError |
|
PyExc_OverflowError |
OverflowError |
|
PyExc_ReferenceError |
ReferenceError |
(2) |
PyExc_RuntimeError |
RuntimeError |
|
PyExc_SyntaxError |
SyntaxError |
|
PyExc_SystemError |
SystemError |
|
PyExc_SystemExit |
SystemExit |
|
PyExc_TypeError |
TypeError |
|
PyExc_ValueError |
ValueError |
|
PyExc_WindowsError |
WindowsError |
(3) |
PyExc_ZeroDivisionError |
ZeroDivisionError |
|
Notes:
- (1)
- This is a base class for other standard exceptions.
- (2)
- This is the same as weakref.ReferenceError.
- (3)
- Only defined on Windows; protect code that uses this by testing that
the preprocessor macro
MS_WINDOWS
is defined.
Release 2.4.1, documentation updated on 30 March 2005.
See About this document... for information on suggesting changes.