Handling errors inside except block | Sololearn: Learn to code for FREE!

+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?

8/23/2016 12:27:16 AM

Solid State

1 Answer

New Answer

+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")