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 either class objects or string objects, depending on the use of the -X option to the interpreter. 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_RuntimeError RuntimeError  
PyExc_SyntaxError SyntaxError  
PyExc_SystemError SystemError  
PyExc_SystemExit SystemExit  
PyExc_TypeError TypeError  
PyExc_ValueError ValueError  
PyExc_ZeroDivisionError ZeroDivisionError  


This is a base class for other standard exceptions. If the -X interpreter option is used, these will be tuples containing the string exceptions which would have otherwise been subclasses.

Send comments on this document to python-docs@python.org.