Question:easy

State whether the following statement is True or False:

In Python, Logical errors can be handled using try…except…finally statement.

Show Hint

try...except...finally catches only exceptions raised while the program runs. A logical error raises no exception, so it cannot be handled this way.
Updated On: Oct 20, 2026
Show Solution

Solution and Explanation

Step 1: Start from what an exception is:
An exception is an object that Python creates when it meets a problem while running a statement.
Examples are ZeroDivisionError, ValueError and TypeError.
The try...except...finally statement reacts only to such objects.
If Python creates no exception, the except block stays unused.

Step 2: Ask whether a logical error creates an exception:
A logical error means the code is valid but the idea behind it is wrong.
Take this code, which should add two numbers.
a = 5
b = 3
print(a - b)

It prints 2 instead of 8. Python sees a valid subtraction, so it raises nothing.
No exception means nothing for the except block to catch.

Step 3: Compare with an error that can be handled:
Now take int('abc'). Python raises ValueError: invalid literal for int() with base 10: 'abc'.
Here try...except can catch the error and show a friendly message.
This shows the difference clearly: runtime errors can be handled, logical errors cannot.

Step 4: Say how logical errors are really removed:
A programmer finds them by testing with sample data, printing values and tracing the code by hand.
Then the wrong formula or condition is corrected in the source code.

Final Answer:
The statement is False, because no exception is raised for a logical error and try...except...finally works only on exceptions.
Was this answer helpful?
0