Courseiva
Handling ExceptionshardMultiple ChoiceObjective-mapped

1Z0-829 Handling Exceptions Practice Question

Exhibit

Refer to the exhibit.

Execution output:
Exception in thread "main" java.io.IOException: IO error
	at Test.main(Test.java:10)
Suppressed: java.io.IOException: Close error
	at Test$MyResource.close(Test.java:20)

Given the exhibit showing output from a program that uses try-with-resources, which of the following best describes the program?

⚠ Common exam trap

Oracle often tests the misconception that only one exception can be thrown, leading candidates to think that if a close method throws, the try block's exception is lost, but in reality both are captured via suppressed exceptions.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Both the try block and the close method threw exceptions.

The output shows both a primary exception from the try block and a suppressed exception from the close method. In try-with-resources, if both the try block and the close method throw exceptions, the primary exception from the try block is propagated, and the close method's exception is added as a suppressed exception. The output displays both exceptions, confirming that both occurred.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • The try block threw an exception, but the resource closed successfully.

    Why it's wrong here

    Close also threw an exception (suppressed).

  • Only the close method threw an exception, and the try block did not throw.

    Why it's wrong here

    Primary exception from main indicates try threw.

  • Both the try block and the close method threw exceptions.

    Why this is correct

    Both exceptions present; close exception is suppressed.

  • The close method threw an exception, and the try block completed normally.

    Why it's wrong here

    Primary exception is from try block, not close.

About these practice questions

One of 513 original 1Z0-829 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.