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... except
blocks - Python recommends EAFP (Easier to Ask for Forgiveness than to ask for Permission) over LBYL (Look Before You Leap)
- You may use an optional
else
block to execute any further code when no exceptions are raised - You may use an optional
finally
block to execute any further code whether or not an exception was raised - You can
raise
your own Exceptions