Bird
0
0

Why should custom exceptions usually extend Exception instead of Throwable directly in Java?

hard📝 Conceptual Q10 of 15
Java - Custom Exceptions
Why should custom exceptions usually extend Exception instead of Throwable directly in Java?
ABecause Throwable includes Errors which are not meant to be caught or handled
BBecause Exception is the root of all errors in Java
CBecause Throwable cannot be thrown explicitly
DBecause Exception classes do not require constructors
Step-by-Step Solution
Solution:
  1. Step 1: Understand Throwable hierarchy

    Throwable has two main subclasses: Error and Exception. Errors represent serious problems not meant to be caught.
  2. Step 2: Reason why custom exceptions extend Exception

    Extending Exception avoids mixing with Errors and fits Java's checked exception mechanism.
  3. Final Answer:

    Because Throwable includes Errors which are not meant to be caught or handled -> Option A
  4. Quick Check:

    Custom exceptions extend Exception, not Throwable directly [OK]
Quick Trick: Extend Exception to avoid mixing with JVM Errors [OK]
Common Mistakes:
  • Extending Throwable directly for custom exceptions
  • Thinking Exception is root of all errors
  • Believing Throwable cannot be thrown

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes