Which of the following statement is correct with respect to exception handling in python?
Which of the following statement is correct with respect to exception handling in python?
Solution
✅ Correct Option: 1
A single try block can be followed by several except clauses, each handling a different exception type. Python checks them in order and runs the first one that matches the exception raised.
try:
x = int(input())
y = 10 / x
except ValueError:
print("Not a number")
except ZeroDivisionError:
print("Cannot divide by zero")
Option 2: finally can be used with any number of except clauses, and it always runs.
Option 3: raise is optional. Python raises exceptions automatically on errors, and raise is only used to trigger one manually.
Option 4: an except clause must always be attached to a try block, otherwise it is a SyntaxError.
Related questions:
2025: 15 May Shift 2
2026: 29 May Shift 2