1Z0-829 Handling Exceptions Practice Question
Consider try-with-resources where resource1 is opened first, then resource2. During closing, both throw exceptions. Which exception is propagated to the caller?
⚠ Common exam trap
The trap here is that candidates often mistakenly think the exception from the first declared resource is propagated, when in fact the exception from the resource closed first (the last declared) is propagated, and the other is suppressed.
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 exception from resource2 (closed first) with resource1's exception as suppressed.
In try-with-resources, resources are closed in the reverse order of their declaration. Resource2 (declared second) is closed first, and resource1 (declared first) is closed last. If both throw exceptions during closing, the exception from the first resource closed (resource2) is propagated to the caller, and the exception from the second resource closed (resource1) is added as a suppressed exception. This matches option B.
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 resource1 (closed last) with resource2's exception as suppressed.
Why it's wrong here
First exception is from resource2, not resource1.
- ✓
The exception from resource2 (closed first) with resource1's exception as suppressed.
Why this is correct
Resources closed in reverse order; first exception encountered becomes primary.
- ✗
Only the exception from the resource declared first is propagated.
Why it's wrong here
Order of declaration does not determine propagation.
- ✗
Both exceptions are wrapped in a new exception.
Why it's wrong here
Not wrapped; one is primary, the other suppressed.
Go deeper
Related to this question
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 →
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.