Which of the following is correct syntax for handling exception in python?
Which of the following is correct syntax for handling exception in python?
Solution
✅ Correct Option: 2
Python handles exceptions with a try block followed by an except block. The code that may fail goes under try:, and the except Exception: block runs if that exception occurs.
Options 1, 3 and 4: Python has no catch keyword. It belongs to Java, C++ and JavaScript.
Option 3: raise is used to throw an exception, not to handle one.
else and finally can follow except: else runs if no exception occurs, and finally always runs.
Related questions:
2025: 3 June Shift 2
2026: 26 May Shift 1
2026: 29 May Shift 1