nerdexam
Oracle

1Z0-819 · Question #144

Which two statements are correct about try blocks? (Choose two.)

The correct answer is A. A try block can have more than one catch block. C. A finally block must be immediately placed after the try or catch blocks. A is correct because a single try block can have multiple catch blocks, each handling a different exception type - this is standard Java exception handling that lets you respond differently to IOException, NullPointerException, etc. C is correct because the finally block must…

Exception Handling

Question

Which two statements are correct about try blocks? (Choose two.)

Options

  • AA try block can have more than one catch block.
  • BA finally block or try-with-resources statement executes before the resources declared are closed.
  • CA finally block must be immediately placed after the try or catch blocks.
  • DA try block must have a catch block and a finally block.
  • ECatch blocks must be in order from generic to specific exception types.

How the community answered

(60 responses)
  • A
    82% (49)
  • B
    5% (3)
  • D
    3% (2)
  • E
    10% (6)

Explanation

A is correct because a single try block can have multiple catch blocks, each handling a different exception type - this is standard Java exception handling that lets you respond differently to IOException, NullPointerException, etc.

C is correct because the finally block must immediately follow the last catch block (or the try block if no catch exists) - the compiler enforces this structure; you cannot place arbitrary code between them.

B is wrong because it has the order backwards: in a try-with-resources, declared resources are closed after the try block exits but before any finally block runs - the finally block executes last, not before resource closure.

D is wrong because a try block only requires at least one of either a catch or a finally block - having both is optional, so try { } finally { } with no catch is perfectly valid.

E is wrong because catch blocks must go from specific to generic (most specific exception first), not generic to specific - putting a broad Exception catch first would make it unreachable for any more specific type below it, which is a compile error in Java.

Memory tip: Think of catch blocks like a funnel - narrow (specific) at the top, wide (generic) at the bottom. And remember: try needs a catch or finally, not necessarily both.

Topics

#try-catch-finally#exception handling#resource management#block structure

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice