Exception hierarchy
We've already encountered many of the most common built-in exceptions, and you'll probably encounter the rest over the course of your regular Python development. As we noticed above, most exceptions are subclasses of the Exception class. But this is not true of all exceptions. Exception itself actually inherits from a class called BaseException (In fact, all exceptions must extend the BaseException class or one of its subclasses). There are two key exceptions, SystemExit and KeyboardInterrupt, that derive directly from BaseException instead of Exception.
SystemExit is an exception that is raised whenever the program exits naturally, typically because we called the sys.exit function somewhere in our code (for example, because ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access