What is an exception in Python?
What is an exception in Python?
Solution
An exception in Python is an error event that occurs while the program is running (at runtime) and disrupts the normal flow of execution. Examples are ZeroDivisionError, ValueError and FileNotFoundError. If it is not handled, the program stops and prints a traceback. It can be handled using try and except.
Option 1: a logical error does not raise an exception. The program runs without crashing but gives a wrong output.
Option 2: a syntax error is detected when the code is parsed, before execution starts, so the program does not run at all.
Option 4: Python has no separate compilation step that students see, and errors found before running are syntax errors, not exceptions.
Related questions:
2026: 31 May Shift 1
2026: 20 May Shift 1