What happens if multiple except blocks are written for the same try block?
What happens if multiple except blocks are written for the same try block?
Solution
✅ Correct Option: 2
Python checks the except blocks from top to bottom. When an exception occurs in the try block, the first except block whose exception type matches runs, and the remaining except blocks are skipped.
This is why a specific exception such as ZeroDivisionError should be written before a general one such as Exception. If the general block comes first, it catches everything and the specific block never runs.
Option 1: only one except block runs for a single exception, never several together.
Option 3: the last block runs only if it is the first one that matches, not because of its position.
Related questions:
2026: 23 May Shift 2