Courseiva
Handling ExceptionshardMultiple ChoiceObjective-mapped

1Z0-829 Handling Exceptions Practice Question

A financial trading application uses Java 17 and processes millions of transactions per second. It uses a custom checked exception `TradeException extends Exception` for business rule violations. Recently, the transaction processing service began throwing a `RuntimeException` that wraps a `TradeException`, but the error logs only show the wrapper's message and stack trace, missing the original `TradeException` details. The logging framework prints the exception and its cause chain. The development team needs to ensure that the original `TradeException` message and stack trace are always logged. What is the most appropriate course of action?

⚠ Common exam trap

It's easy for candidates to think catching the wrapper and manually extracting the cause's message (Option A) is sufficient, but they overlook that the logging framework needs the full cause chain to print the original stack trace, not just the message string.

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

Modify the exception wrapping code to pass the original TradeException as a cause to the RuntimeException constructor.

Passing the original `TradeException` as the cause argument to the `RuntimeException` constructor (e.g., `new RuntimeException(message, cause)`) preserves the full cause chain. The logging framework, which prints the exception and its cause chain, will then output both the wrapper's stack trace and the original `TradeException`'s message and stack trace, ensuring complete visibility.

Answer analysis

Option-by-option breakdown

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

  • Catch the RuntimeException in the main processing loop and print the cause's message using getCause().getMessage().

    Why it's wrong here

    This workaround does not fix the root cause and may miss other places where the exception is logged.

  • Modify the exception wrapping code to pass the original TradeException as a cause to the RuntimeException constructor.

    Why this is correct

    Using the cause constructor preserves the original exception in the cause chain.

  • Modify the TradeException class to extend RuntimeException.

    Why it's wrong here

    Changing the exception type may break existing method signatures that declare checked exceptions.

  • Override the getMessage() method in TradeException to return the original message.

    Why it's wrong here

    The wrapper's getMessage() is used, not the original's.

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 →

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.