1Z0-811 · Question #41
Which statement is true about exception handling?
The correct answer is D. All catch blocks must be ordered from general to most specific. Option D is correct because in Java (and most languages with structured exception handling), catch blocks must be ordered from most specific to most general - placing a broader exception type (like Exception) before a narrower one (like IOException) causes a compile-time error…
Question
Options
- AAt least one catch block must accompany a try statement.
- BAll statements in a try block are executed, even if an exception occurs in the middle of the try block.
- CAt least one statement in a try block must throw an exception.
- DAll catch blocks must be ordered from general to most specific.
How the community answered
(42 responses)- A2% (1)
- B5% (2)
- C2% (1)
- D90% (38)
Explanation
Option D is correct because in Java (and most languages with structured exception handling), catch blocks must be ordered from most specific to most general - placing a broader exception type (like Exception) before a narrower one (like IOException) causes a compile-time error, since the specific catch would be unreachable.
Why the others are wrong:
- A is false - a
tryblock can be paired with only afinallyblock, with nocatchat all. - B is false - execution jumps out of the
tryblock the moment an exception is thrown; remaining statements are skipped. - C is false - a
tryblock may complete normally without any exception ever being thrown.
Memory tip: Think "specific before general" - just like a funnel, you catch the narrow stuff first, then widen out. If you put the wide net first, the specific exceptions never get a turn.
Topics
Community Discussion
No community discussion yet for this question.