Search⌘ K

The Exception Hierarchy

Explore Python's exception hierarchy to understand how exceptions relate through BaseException. Learn the differences between Exception and BaseException subclasses, focusing on SystemExit and KeyboardInterrupt. This lesson equips you with knowledge to properly handle exceptions and avoid common pitfalls in error management.

We’ve already seen several of the most common built-in exceptions, and we’ll probably encounter the rest over the course of our regular Python development. As we noticed earlier, most exceptions are subclasses of the Exception class. But this is not true of all exceptions. The Exception class actually extends a class called BaseException. In fact, all exceptions must extend the BaseException class or one of its subclasses.

Types of BaseException

There are two key built-in exception classes:

  • SystemExit
...