0

Exception Handling Concept

Hi, Can you please share the output of this code? also please describe the reason . Thanks! try: print(d''1/0) except invalid syntax: print(2) finally: print(3)

10th Aug 2020, 7:15 AM
Abhishek
4 ответов
+ 3
Syntax error can not be catched with try ... except (only by working with eval() or exec()). Syntax error raise during the parser run before the code will be executed. So syntax errors must be fixed in any case before the program run.
10th Aug 2020, 12:44 PM
Lothar
Lothar - avatar
+ 5
Abhishek There is indeed a syntax error in your try block, plus, there is no exception named invalid syntax. You can just write except: if you don't know the type of error the code will encounter. Check this out for list of errors in Python and go through this tutorial https://www.sololearn.com/learn/Python/2441/?ref=app https://code.sololearn.com/cM1FBEbiZvk0/?ref=app
10th Aug 2020, 7:24 AM
Tomiwa Joseph
Tomiwa Joseph - avatar
+ 1
ok , lets try same code with using except only? try: print(d''1/0) except: print(2) finally: print(3) but this code also not executing
10th Aug 2020, 7:39 AM
Abhishek
+ 1
Thanks ...i got the point
10th Aug 2020, 12:51 PM
Abhishek