Exception Hierarchy
suggest changePython matches an except clause against the raised exception's class and its base classes. Catching a base class therefore also catches exceptions derived from it.
For example, FileNotFoundError and PermissionError are subclasses of OSError, so an except OSError clause catches either one. In Python 3, IOError is an alias of OSError; the separate EnvironmentError and WindowsError hierarchy from Python 2 no longer exists.
The most important parts of the built-in hierarchy are:
BaseException
├── BaseExceptionGroup
├── GeneratorExit
├── KeyboardInterrupt
├── SystemExit
└── Exception
├── ArithmeticError
│ ├── FloatingPointError
│ ├── OverflowError
│ └── ZeroDivisionError
├── AssertionError
├── AttributeError
├── EOFError
├── ExceptionGroup
├── ImportError
│ └── ModuleNotFoundError
├── LookupError
│ ├── IndexError
│ └── KeyError
├── NameError
│ └── UnboundLocalError
├── OSError
│ ├── FileExistsError
│ ├── FileNotFoundError
│ ├── PermissionError
│ └── TimeoutError
├── RuntimeError
│ ├── NotImplementedError
│ └── RecursionError
├── StopIteration
├── TypeError
├── ValueError
│ └── UnicodeError
└── Warning
This is a summary rather than an exhaustive list. Most application code should catch a specific subclass of Exception. Avoid catching BaseException, because doing so also intercepts KeyboardInterrupt and SystemExit, which normally terminate the program. Exception groups were added in Python 3.11 and can contain multiple unrelated exceptions. ExceptionGroup subclasses both Exception and BaseExceptionGroup.