Exception class hierarchy

When an exception occurs, it starts at the innermost level possible (a child) and travels upward (through the parents), waiting to be caught. This means a couple of things to a programmer:

The following exceptions list shows the hierarchy of exceptions from the Python Library Reference, for Python 3.6. One thing to note is that this hierarchy sometimes changes between Python versions; for example, ArithmeticError is a child of StandardError in version 2.7, but is a child of Exception in version 3.6:

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 
      |    +-- IndentationError 
      |         +-- TabError 
      +-- SystemError 
      +-- TypeError 
      +-- ValueError 
      |    +-- UnicodeError 
      |         +-- UnicodeDecodeError 
      |         +-- UnicodeEncodeError 
      |         +-- UnicodeTranslateError 
      +-- Warning 
           +-- DeprecationWarning 
           +-- PendingDeprecationWarning 
           +-- RuntimeWarning 
           +-- SyntaxWarning 
           +-- UserWarning 
           +-- FutureWarning 
           +-- ImportWarning 
           +-- UnicodeWarning 
           +-- BytesWarning 
           +-- ResourceWarning 

This hierarchy is important to understand when you're writing your code; an exception may not be available depending on which Python version you're using. If you're trying to make your programs as portable as possible, you have to be cognizant of which Python version the target system is running.