1Z0-829 Handling Exceptions Practice Question
Given a try-with-resources statement where both the try block and the close method of the resource throw exceptions, which of the following is true about exception handling?
⚠ Common exam trap
Many exam-takers think both exceptions are thrown simultaneously or that the close exception is ignored, but Java's suppressed exception mechanism ensures the try block exception remains primary while preserving the close exception for debugging.
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
✓
The try block exception is the primary exception; the close exception is suppressed.
In a try-with-resources statement, if both the try block and the resource's close() method throw exceptions, the exception from the try block is the primary exception, and any exception thrown by close() is added as a suppressed exception. This is defined by Java's try-with-resources semantics (JLS §14.20.3.2), ensuring the primary exception is not masked by resource cleanup failures.
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 exception from the close method is the primary exception.
Why it's wrong here
The try block exception is primary.
- ✗
Both exceptions are thrown simultaneously, causing a multi-catch.
Why it's wrong here
Only one exception is propagated; the other is suppressed.
- ✓
The try block exception is the primary exception; the close exception is suppressed.
Why this is correct
Correct behavior of try-with-resources.
- ✗
The close method exception is ignored if the try block succeeds.
Why it's wrong here
If try succeeds, close exception is thrown normally.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 1Z0-829 question from scratch — 513 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
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.