diff --git a/Exception Handling b/Exception Handling new file mode 100644 index 0000000..376eb29 --- /dev/null +++ b/Exception Handling @@ -0,0 +1,15 @@ +# 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)