Recall
Some key points in this chapter:
- Raising an exception happens when something goes wrong. We looked at division by zero as an example. Exceptions can also be raised with the
raisestatement. - The effects of an exception are to interrupt the normal sequential execution of statements. It saves us from having to write a lot of
ifstatements to check to see if things can possibly work or check to see if something actually failed. - Handling exceptions is done with the
try:statement, which has anexcept:clause for each kind of exception we want to handle. - The exception hierarchy follows object-oriented design patterns to define a number of subclasses of the
Exceptionclass we can work with. Some additional exceptions,SystemExitandKeyboardInterrupt, are not subclasses of theExceptionclass; handling these introduces risks and doesn't solve very many problems, so we generally ignore them. - Defining our own exceptions is a matter of extending...