Python - Exception Exception Basics


Python exceptions are events that can modify the flow of control.

Exceptions are triggered automatically on errors.

The exceptions are processed by four statements.

Statement Description
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/as Implement context managers in Python 2.6, 3.0, and later (optional in 2.5).