4.1 Raising exceptions
Python’s normal behavior is to execute statements in the order they are found, either in a file or interactively at the >>> prompt. A few statements, specifically if, while, and for, alter the simple top-to-bottom sequence of statement execution. Additionally, an exception can break the sequential flow of execution. When an exception is raised, it interrupts the sequential execution of statements.
In Python, the exception that’s raised is also an object. There are many different exception classes available, and we can easily define more of our own. The one thing they all have in common is that they inherit from a built-in class called BaseException. (As a practical matter, we’re far more interested in exceptions based on the Exception class.)
When an exception is raised, everything that was supposed to happen is preempted. Instead, exception handling replaces normal processing.
The easiest way to cause...