Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python Catching Exceptions

# import module sys to get the type of exception
import sys

randomList = ['x', 0, 4]

for entry in randomList:
    try:
        print("The entry is", entry)
        r = 1/int(entry)
        break
    except Exception as e:
        print(e.__class__, "occurred.")
        print("Next entry.")
        print()
print("The reciprocal of", entry, "is", r)
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #python #Catching #Exceptions
ADD COMMENT
Topic
Name
6+5 =