Why didn't the print statement got executed? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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
5 Answers
+ 4
Or you can do raise TypeError("\nlast") Since you want to print it in newline tbh
11th Apr 2019, 8:42 AM
Name Omitted until I come back
+ 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