""" lectureNote/chapters/chapt05/codes/try_except2.py try-except example, originally from https://docs.python.org/3/tutorial/errors.html """ def this_fails(): print('try-except example') print('1. valid division 1/2') print('2. invalid division 1/0') option = int(input("Please enter an option number -- 1 or 2: ")) if option == 1: x = 1./2 elif option == 2: x = 1./0 return x try: x = this_fails() print(x) except ZeroDivisionError: print('Handling run-time error')