A Comprehensive Guide to Handling Exceptions in Python
eg -
import sys
randomList = [1, 2, 8]
for entry in randomList:
try:
print(randomList[entry])
except:
print("Oops!", sys.exc_info()[0], "occurred.")
Output
228 Oops! <class 'IndexError'> occurred.
No comments:
Post a Comment