This is a searchable reference for Python’s built-in exception hierarchy — the class tree that every error in the standard library belongs to. For each exception it shows the direct parent class, the attributes it carries, and a plain-English description of what typically triggers it, so you can decide exactly what to catch and how to handle it.
How it works
Every Python exception derives from BaseException. Below it sits Exception, the base for ordinary catchable errors, and a small set of special signals — SystemExit, KeyboardInterrupt, GeneratorExit — that derive directly from BaseException so they are not swallowed by a plain except Exception. The table groups errors by family: arithmetic errors under ArithmeticError, lookup errors (KeyError, IndexError) under LookupError, and the large OSError family covering file and network failures, each carrying an errno.
When you catch an exception, catch the most specific class you can actually handle. Catching a parent like OSError handles a whole family at once, which is useful for I/O, while catching Exception is a last resort that should usually re-raise or log.
Example
A practical guard against a missing key versus a missing file:
try:
value = config["timeout"] # may raise KeyError
fh = open(path) # may raise FileNotFoundError
except KeyError:
value = 30 # sensible default
except FileNotFoundError as e:
print(f"missing {e.filename}") # OSError subclass with errno/filename
Because FileNotFoundError is a subclass of OSError, an except OSError would also catch it — handy when you do not care which specific I/O error occurred. Everything runs in your browser; nothing is uploaded.