+ 1

Why didn't the print statement got executed?

try: print(2/0) except: print('error') finally: raise TypeError print('last') This produced:error and TypeError. Why didn't the word 'last' got executed. Other e.g: try: print(2/0) except: print('error') finally: raise TypeError print('last') This also gave the same output.

9th Apr 2019, 2:18 PM
paperinflames
paperinflames - avatar
4 Respuestas
+ 2
'raise TypeError' forces the TypeError exception which terminates the program as any other exception. So the last statement is never executed.
9th Apr 2019, 2:43 PM
portpass
+ 1
in this case yes
9th Apr 2019, 2:52 PM
Bebida Roja
Bebida Roja - avatar
+ 1
Sindhu Yes, it stops evaluating of the code
9th Apr 2019, 2:54 PM
portpass
0
check out error handling
9th Apr 2019, 2:54 PM
Bebida Roja
Bebida Roja - avatar