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

Exception Handling

why the code in the except block is not running. need help. link-https://code.sololearn.com/c178P8mqR6g6

1st Dec 2020, 5:38 PM
Pratik Maity
Pratik Maity - avatar
6 Answers
+ 6
There is a colon missing in the function definition at the end of the line: def find_number_even_or_odd(x, y): <--- this colon is missing!
1st Dec 2020, 6:13 PM
Lothar
Lothar - avatar
+ 4
Lothar i think Pratik Maity may trying or meant "it's a syntax error, then why except Syntaxerror not handling that..?"
1st Dec 2020, 6:18 PM
Jayakrishna 🇮🇳
+ 1
Syntax error is special. When you run the program, the Python interpreter first checks if it even speaks the same language as you. So if your syntax doesn't make sense, you get a nice error, even before your code is evaluated. Therefore try-except doesn't work for SyntaxError. Read more on the topic here: https://realpython.com/invalid-syntax-python/ "When you run your Python code, the interpreter will first parse it to convert it into Python byte code, which it will then execute. The interpreter will find any invalid syntax in Python during this first stage of program execution, also known as the parsing stage. If the interpreter can’t parse your Python code successfully, then this means that you used invalid syntax somewhere in your code. The interpreter will attempt to show you where that error occurred."
2nd Dec 2020, 3:32 AM
Tibor Santa
Tibor Santa - avatar
0
I don't understand please explain
1st Dec 2020, 5:56 PM
Pratik Maity
Pratik Maity - avatar
0
Jayakrishna, I think you understand what I mean
1st Dec 2020, 6:57 PM
Pratik Maity
Pratik Maity - avatar
0
Syntax errors can't be cured by try and except
17th Mar 2022, 10:34 PM
Goodness Ogunlana