Python Exception Hierarchy
PCEP objective 4.3 is titled Python Built-In Exceptions Hierarchy, and it is one of the few objectives that really is a memorisation task. It is much less work than it looks: the tree has three or four levels, most exceptions sit directly under Exception, and the ones that do not are grouped in ways that make sense. This page prints the whole thing out of the interpreter rather than drawing it, because every diagram in circulation gets at least one relationship wrong.
Exceptions Guide 23 of 26 Intermediate
- OSUbuntu 26.04 LTS
- Python3.14.4
- pip25.1.1
- TimeAbout 15 min
The hierarchy is stable. ModuleNotFoundError was added in Python 3.6 as a subclass of ImportError, and BaseExceptionGroup in 3.11 - neither exam examines the second. RecursionError was split out of RuntimeError in 3.5 and remains a subclass of it.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| RUNNER01 | 192.168.0.27 | Ubuntu 26.04 LTS | Python 3.14.4 - the only machine this path needs | 2 Core | 4 GB | 50 GB |
This guide includes
Use this for the exception-hierarchy objective, the most directly memorisable material on PCEP. This matters because inheritance decides which except clause matches - so a class's parents tell you what will catch it.
- printing the tree from the classes themselves, rather than reading a diagram
- learning what sits directly under
BaseException - seeing inheritance decide which clause matches
- memorising the part of the shape that is actually worth memorising
Before you start
- guide 18 - exceptions are raised by things that fail.
- You will have met most of these already: this path has raised twenty different exceptions before this page.
-
The tree, printed from the classes themselves
-
What sits directly under BaseException
-
Inheritance decides which clause matches
-
The shape worth memorising
-
What the exam does with this objective