nerdexam
Oracle

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…

Exception Handling and Methods

Question

Which statement is true about exception handling?

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)
  • A
    2% (1)
  • B
    5% (2)
  • C
    2% (1)
  • D
    90% (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 try block can be paired with only a finally block, with no catch at all.
  • B is false - execution jumps out of the try block the moment an exception is thrown; remaining statements are skipped.
  • C is false - a try block 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

#exception handling#try-catch blocks#exception hierarchy#catch block ordering

Community Discussion

No community discussion yet for this question.

Full 1Z0-811 Practice