From f56369b8bda7502bc76d626243e040b99cf49d4c Mon Sep 17 00:00:00 2001 From: Madhu0299 <69695602+Madhu0299@users.noreply.github.com> Date: Fri, 2 Oct 2020 00:41:35 +0530 Subject: [PATCH] Exception Handling Create a program to explain exception handling --- Exception Handling | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Exception Handling 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)