Courseiva
Handling ExceptionseasyMultiple ChoiceObjective-mapped

1Z0-829 Handling Exceptions Practice Question

Which of the following is a best practice when designing custom exception classes?

⚠ Common exam trap

Oracle often tests the misconception that extending Throwable directly is acceptable for custom exceptions, but the trap is that Throwable should only be subclassed by Error and Exception, and custom exceptions must extend Exception or RuntimeException to work correctly with Java's checked/unchecked exception rules and the compiler's exception specification enforcement.

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

Extend an existing exception class and provide constructors that call the superclass constructor.

The Java best practice for custom exceptions is to extend an existing exception class (e.g., Exception or RuntimeException) and provide constructors that call the superclass constructor. This ensures the custom exception inherits the standard exception mechanism, including proper chaining, stack trace handling, and compatibility with try-catch blocks, without reinventing the wheel.

Answer analysis

Option-by-option breakdown

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

  • Define a custom exception with a single constructor that takes an int error code.

    Why it's wrong here

    Missing message or cause; not following standard conventions.

  • Extend an existing exception class and provide constructors that call the superclass constructor.

    Why this is correct

    This matches common patterns and allows proper exception handling.

  • Extend the Throwable class directly to create a new exception type.

    Why it's wrong here

    Extending Throwable directly is unusual; prefer Exception or RuntimeException.

  • Use a generic Exception class with a string message to indicate the type of error.

    Why it's wrong here

    Using generic Exception defeats purpose of custom exceptions for specific handling.

About these practice questions

This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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.