4.1 標準例外

標準のPythonの例外は全て、名前が"PyExc_"にPytnonの例外の名前が つづく大域変数として利用できる。これらは、PyObject*型を持つ。 つまり、それらは全てクラスオブジェクトである。 完全を期すため、ここに全ての変数を示す:

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  

注意:

(1)
これは他の標準例外の基底クラスである。 もし-Xインタープリタオプションが使われたなら、これらは (そうでなければサブクラスであったであろう)文字列の例外を含む タプルである。