Known exceptions

Note

I am currently focusing on adding more cases of SyntaxError, and possibly TypeError, rather than other other specific types of exceptions, as I believe that these are the most likely ones to be encountered by beginners and include so many different possible cases.

Warning

This documentation is not updated as often as the actual content of the program. The content of the following two pages is updated a lot more frequently than the rest of the documentation and might be a more useful reference than what is written below.

In the following, those that are followed by an * had been implemented when this page was last updated.

Those followed by !!, namely SystemExit and KeyboardInterrupt, have been excluded as it seemed rather counter-productive to intercept them.

Those followed by #, namely GeneratorExit, StopIteration, FloatingPointError, and StopAsyncIteration, are excluded as they should not normally be seen by an end user - at least, not by beginners who would need additional explanation about the meaning of such exceptions. Furthermore, in the case of StopIteration, see PEP 479.

FloatingPointError is actually not used by Python.

BaseException, Exception, and ArithmeticError are base classes which are not normally seen: some derived classes are normally used instead. They are denoted by **.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
BaseException **
 +-- SystemExit !!
 +-- KeyboardInterrupt !!
 +-- GeneratorExit #
 +-- Exception **
      +-- StopIteration #
      +-- StopAsyncIteration #
      +-- ArithmeticError **
      |    +-- FloatingPointError #
      |    +-- OverflowError *
      |    +-- ZeroDivisionError *
      +-- AssertionError
      +-- AttributeError
      +-- BufferError
      +-- EOFError
      +-- ImportError *
      |    +-- ModuleNotFoundError *
      +-- LookupError *
      |    +-- IndexError *
      |    +-- KeyError *
      +-- MemoryError
      +-- NameError  *
      |    +-- UnboundLocalError *
      +-- OSError
      |    +-- BlockingIOError
      |    +-- ChildProcessError
      |    +-- ConnectionError
      |    |    +-- BrokenPipeError
      |    |    +-- ConnectionAbortedError
      |    |    +-- ConnectionRefusedError
      |    |    +-- ConnectionResetError
      |    +-- FileExistsError
      |    +-- FileNotFoundError *
      |    +-- InterruptedError
      |    +-- IsADirectoryError
      |    +-- NotADirectoryError
      |    +-- PermissionError
      |    +-- ProcessLookupError
      |    +-- TimeoutError
      +-- ReferenceError
      +-- RuntimeError
      |    +-- NotImplementedError
      |    +-- RecursionError
      +-- SyntaxError * (partial: many more cases to include)
      |    +-- IndentationError *
      |         +-- TabError *
      +-- SystemError
      +-- TypeError * (partial: many more cases to include)
      +-- ValueError
      |    +-- UnicodeError
      |         +-- UnicodeDecodeError
      |         +-- UnicodeEncodeError
      |         +-- UnicodeTranslateError
      +-- Warning
           +-- DeprecationWarning
           +-- PendingDeprecationWarning
           +-- RuntimeWarning
           +-- SyntaxWarning
           +-- UserWarning
           +-- FutureWarning
           +-- ImportWarning
           +-- UnicodeWarning
           +-- BytesWarning
           +-- ResourceWarning