< BACKMake Note | BookmarkCONTINUE >
152015024128143245168232148039196038240039088173205162105045222218072221080086060241090

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, all the variables are in Table A.1.

Table A.1. C Variables for the Standard Python Exceptions
C Name Python Name See Note below
PyExc_Exception Exception *
PyExc_StandardError StandardError *
PyExc_ArithmeticError ArithmeticError *
PyExc_LookupError LookupError *
PyExc_AssertionError AssertionError  
PyExc_AttributeError AttributeError  
PyExc_EOFError EOFError  
PyExc_EnvironmentError EnvironmentError *
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 command option is used, these will be tuples containing the string exceptions that would have otherwise been subclasses.

Deprecation of String Exceptions

The -X command-line option will be removed in Python 1.6/2.0. All exceptions built into Python or provided in the standard library will be classes derived from Exception.

String exceptions will still be supported in the interpreter to allow existing code to run unmodified, but this will also change in a future release.


Last updated on 1/30/2002
Python Developer's Handbook, © 2002 Sams Publishing

< BACKMake Note | BookmarkCONTINUE >

Index terms contained in this section

Application Programmers Interface (API)
     Python/C
            variables, exceptions
exceptions
      variables, Python/C Applications Programmers Interface (API)
global variables, Python/C Application Programmers Interface (API)
interfaces
     Python/C Application Programmers (API)
            variables, exceptions
Python/C Application Programmers Interface (API)
      variables, exceptions
variables
      exceptions, Python/C Application Programmers Interface (API)

© 2002, O'Reilly & Associates, Inc.