Catching Exception | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Catching Exception

https://code.sololearn.com/ce6m8vXTUZxU/?ref=app why exception block is not executing

21st Jan 2018, 5:33 AM
Nitin G Dagaya
Nitin G Dagaya - avatar
4 Answers
+ 5
print ("hello") instead of print "hello"
21st Jan 2018, 5:37 AM
Nigel Yong
Nigel Yong - avatar
+ 5
An error occured in the try part, so it switches to the except part instead of crashing the program. Hope it helps! num = 5 try: num = num/0 print ("hello") except: print("hello world")
21st Jan 2018, 5:40 AM
Nigel Yong
Nigel Yong - avatar
+ 1
SyntaxError is not a runtime error, but a compile time error, thus it cannot be caught in the code that has not been compiled.
21st Jan 2018, 5:52 AM
Sean Furze
Sean Furze - avatar
0
that's exception I want to catch and print proper output in except block
21st Jan 2018, 5:41 AM
Nitin G Dagaya
Nitin G Dagaya - avatar