nerdexam
Oracle

1Z0-819 · Question #119

Which of the following statements are true about the finally block?

The correct answer is D. In a try-with-resources statement, any catch or finally block is run after the resources declared have been closed. F. If an exception is thrown from the finally block, the remaining part of the finally block will not be executed. D is correct because the Java Language Specification guarantees that in a try-with-resources statement, resources are closed (in reverse declaration order) before any associated catch or finally blocks execute - the word "any" is key here, as it correctly signals these blocks…

Exception Handling

Question

Which of the following statements are true about the finally block?

Options

  • AA finally block is required when there are no catch blocks in a try-with-resources statement.
  • BMore than one finally block can be declared with a regular try statement.
  • CA finally block cannot be declared with a try-with-resources statement.
  • DIn a try-with-resources statement, any catch or finally block is run after the resources declared have been closed.
  • EA finally block is executed after the resources declared have been closed in a try-with-resources statement.
  • FIf an exception is thrown from the finally block, the remaining part of the finally block will not be executed

How the community answered

(52 responses)
  • A
    2% (1)
  • B
    6% (3)
  • C
    2% (1)
  • D
    81% (42)
  • E
    10% (5)

Explanation

D is correct because the Java Language Specification guarantees that in a try-with-resources statement, resources are closed (in reverse declaration order) before any associated catch or finally blocks execute - the word "any" is key here, as it correctly signals these blocks are optional but, when present, always run post-closure.

F is correct because a finally block is not immune to its own exceptions: the moment one is thrown inside it, control exits that block immediately, and any remaining statements are skipped - just as in any other code block.

Why the distractors are wrong:

  • A - false; try-with-resources requires neither a catch nor a finally block, since automatic resource management is built into the syntax itself.
  • B - false; a try statement can have at most one finally block.
  • C - false; a finally block is permitted (though optional) with try-with-resources.
  • E - subtly wrong: it asserts a finally block is executed, implying it's mandatory or guaranteed, but finally is optional in try-with-resources and not always present.

Memory tip: Think of try-with-resources as a three-act sequence - close resources → catch → finally - and remember that "finally" means "last to run," not "always exists." If anything throws inside finally, it behaves like any other method: execution stops at the throw.

Topics

#try-with-resources#finally block#exception handling#resource management

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice