Question 144 of 509
Handling ExceptionshardMultiple ChoiceObjective-mapped

Quick Answer

The correct answer is that the try block exception becomes the primary exception, while the close method exception is suppressed. This behavior is defined by Java’s try-with-resources semantics in JLS §14.20.3.2, which prioritizes the exception that most directly indicates the operation’s failure—typically the one from the business logic in the try block—over any secondary exception thrown during resource cleanup. On the Oracle Certified Professional Java SE 17 Developer 1Z0-829 exam, this concept tests your understanding of suppressed exceptions in try-with-resources, a frequent topic in exception-handling questions. A common trap is assuming both exceptions propagate independently or that the close exception replaces the try block exception; instead, the primary exception is thrown with the close exception attached as a suppressed exception, retrievable via Throwable.getSuppressed(). Memory tip: think of the try block as the “star of the show” and close() as a “backstage issue”—the main performance (exception) is what you see, while backstage problems are noted but not allowed to steal the spotlight.

1Z0-829 Handling Exceptions Practice Question

This 1Z0-829 practice question tests your understanding of handling exceptions. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

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?

Question 1hardmultiple choice
Full question →

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.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

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.

    Related concept

    Read the scenario before looking for a memorised answer.

  • The close method exception is ignored if the try block succeeds.

    Why it's wrong here

    If try succeeds, close exception is thrown normally.

Common exam traps

Common exam trap: answer the scenario, not the keyword

The trap here is that candidates often 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.

Detailed technical explanation

How to think about this question

Under the hood, the try-with-resources statement is compiled into a try-finally block where resources are closed in the finally section. If both the try block and a close() call throw exceptions, the compiler-generated code catches the close exception and adds it as a suppressed exception to the try block exception using Throwable.addSuppressed(). This mechanism is critical in real-world scenarios like database connections or file I/O, where a primary business logic failure must not be lost due to a secondary cleanup failure.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A network engineer segments a warehouse floor into three subnets: 20 scanners, 5 printers, and 2 management hosts. Picking the wrong mask wastes addresses or leaves too few usable hosts. Exam questions test whether you can apply CIDR notation, calculate block size, and identify the correct usable-host range for a given prefix.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related 1Z0-829 practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free 1Z0-829 practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this 1Z0-829 question test?

Handling Exceptions — This question tests Handling Exceptions — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: 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.

What should I do if I get this 1Z0-829 question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more ways this is tested on 1Z0-829

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. In the exhibit, if an IOException occurs during closing of both resources, which resource's close exception is returned by e.getSuppressed()?

hard
  • A.The suppressed array contains both exceptions.
  • B.Only the exception from FileInputStream close is in the suppressed array.
  • C.The suppressed array contains the exception from FileInputStream.
  • D.Only the exception from BufferedInputStream close is in the suppressed array.

Why C: The primary exception is from the try block (if any) or from the first resource close. Since no exception in try block, the first close (bis) throws primary exception? Actually with try-with-resources, if no exception in try, the first exception encountered during close becomes primary. Resources closed in reverse order: bis first, then fis. If both throw, bis exception is primary, fis exception is suppressed. Option B is correct.

Last reviewed: Jun 25, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.