+ 2

Handling errors inside except block

try: print(1) print(10 / 0) except ZeroDivisionError: print(unknown_var) except NameError: print('Filtered an error from the first except block') finally: print("This is executed last") I intended to filter the error within 'except ZeroDivisionError' block but failed. How can I print the string in the second except block?

23rd Aug 2016, 12:27 AM
Eunjae Lee
Eunjae Lee - avatar
1 ответ
+ 3
Is this what you are trying to do? Code: try: print(1) print(10 / 0) except ZeroDivisionError: try: print(unknown_var) except NameError: print('Filtered an error from the first except block') finally: print("This is executed last")
23rd Aug 2016, 1:39 AM
Replicadoe