DekGenius.com
[ Team LiB ] Previous Section Next Section

Chapter 24. Exception Basics

Part VII deals with exceptions, which are events that can modify the flow of control through a program. In Python, exceptions are triggered automatically on errors, and can be both triggered and intercepted by your code. They are processed by three statements we'll study in this part, the first of which has two variations:


try/except

Catch and recover from exceptions raised by Python, or by you.


try/finally

Perform cleanup actions whether exceptions occur or not.


raise

Trigger an exception manually in your code.


assert

Conditionally trigger an exception in your code.

With a few exceptions (pun intended), we'll find that exception handling is simple in Python, because it's integrated into the language itself as another high-level tool.

    [ Team LiB ] Previous Section Next Section