Introduction
In this module, we will discuss the topic of Exception handling, or in simpler terms, what to do when your Python program generates an error?
Summary:
- Runtime Exceptions are handled by wrapping your code in
try... exceptblocks - Python recommends EAFP (Easier to Ask for Forgiveness than to ask for Permission) over LBYL (Look Before You Leap)
- You may use an optional
elseblock to execute any further code when no exceptions are raised - You may use an optional
finallyblock to execute any further code whether or not an exception was raised - You can
raiseyour own Exceptions