Python Tutorial · Revision notes
Python Exception Handling
An exception is an error detected at run time that interrupts normal flow. Python lets you catch it with try/except/else/finally, raise your own, handle several types and rely on a rich hierarchy of built-in exceptions.
Quick revision
- try -> except -> else (no error) -> finally (always).
- Order except clauses specific to general; avoid bare except.
- raise Err("msg"); bare raise re-raises; raise X from Y chains.
- finally runs even after return/break/continue.
- KeyError/IndexError are LookupError; ZeroDivisionError is ArithmeticError.