Python Exceptions
This module introduces the concept of exceptions and how to handle them in your Python programs.
Exceptions in Python
Catching Exceptions in Python
# import module sys to get the type of exception
import sys
randomList = ['a', 0, 2]
for entry in randomList:
try:
print("The entry is", entry)
r = 1/int(entry)
break
except:
print("Oops!", sys.exc_info()[0], "occurred.")
print("Next entry.")
print()
print("The reciprocal of", entry, "is", r)Catching Specific Exceptions in Python
Raising Exceptions in Python
Python try with else clause
Python try...finally
Last updated