State whether the following statement is True or False :
In Python, Logical errors can be handled using try......except......finally statement.
State whether the following statement is True or False :
In Python, Logical errors can be handled using try......except......finally statement.
False.
Logical errors cannot be caught by a try...except...finally block because they do not raise exceptions — the program runs and produces output, but the output or behaviour is incorrect.
Marking Scheme
- 11 mark: answer 'False' along with correct reasoning that logical errors don't raise exceptions.
Hint
Ask whether the error stops the program (raises an exception) or just gives a wrong silent result — only the former can be handled by try-except.
Quick Oral Answer
False — try-except-finally only handles runtime exceptions that Python raises; a logical error produces a wrong result silently without raising any exception, so it cannot be 'caught'.
Analysis & Explanation
This question tests the distinction between the different categories of errors in Python.
Types of errors
- Syntax errors — violate Python's grammar rules; the program does not run at all (e.g., a missing colon).
- Runtime errors (exceptions) — occur during execution (e.g.,
ZeroDivisionError,ValueError); these CAN be caught and handled usingtry...except...finally. - Logical errors — the program runs without crashing but produces a wrong result because the logic/algorithm itself is flawed (e.g., using
+instead of*in a formula).
Why the statement is False
try...except...finallyonly intercepts exceptions that Python's interpreter actually raises during execution.- A logical error does not raise any exception, so there is nothing for
exceptto catch — the program simply completes and returns an incorrect answer. - Logical errors can only be found through careful code review, tracing, testing, and debugging — not through exception handling.
Common Mistakes
- 1Believing that try-except-finally can catch any kind of error, including logical errors.
- 2Confusing logical errors with runtime errors — logical errors don't crash the program, so there's nothing to 'except'.
Interesting Facts
Logical errors are often considered the hardest to fix because the program runs successfully and shows no error message at all — the mistake is purely in the programmer's reasoning.
Python's try-except mechanism is built entirely around the exception object hierarchy (all exceptions derive from BaseException), so any error type that does not raise such an object cannot be caught this way.
Spotted a mistake or something unclear?
Tell us — we fix reported answers fast.
Frequently Asked Questions
Can any error in Python be fixed using try-except?
No. try-except can only catch runtime errors (exceptions) that Python's interpreter raises during execution, such as ZeroDivisionError or ValueError. Syntax errors prevent the program from running at all, and logical errors don't raise any exception, so neither can be handled by try-except.
How are logical errors detected then?
Logical errors are found through testing with sample inputs, tracing the code manually (dry run), using print statements or a debugger to inspect intermediate values, and careful code review — not through exception-handling constructs.