Java - Custom ExceptionsWhy should custom exceptions usually extend Exception instead of Throwable directly in Java?ABecause Throwable includes Errors which are not meant to be caught or handledBBecause Exception is the root of all errors in JavaCBecause Throwable cannot be thrown explicitlyDBecause Exception classes do not require constructorsCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand Throwable hierarchyThrowable has two main subclasses: Error and Exception. Errors represent serious problems not meant to be caught.Step 2: Reason why custom exceptions extend ExceptionExtending Exception avoids mixing with Errors and fits Java's checked exception mechanism.Final Answer:Because Throwable includes Errors which are not meant to be caught or handled -> Option AQuick 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 exceptionsThinking Exception is root of all errorsBelieving Throwable cannot be thrown
Master "Custom Exceptions" in Java9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Java Quizzes Abstraction - Partial abstraction - Quiz 12easy Constructors - This keyword usage - Quiz 6medium Constructors - Default constructor - Quiz 13medium Constructors - This keyword usage - Quiz 12easy Custom Exceptions - Exception propagation - Quiz 13medium Encapsulation - Encapsulation best practices - Quiz 4medium Exception Handling - Multiple catch blocks - Quiz 2easy Exception Handling - Multiple catch blocks - Quiz 13medium Inheritance - Constructor chaining - Quiz 11easy Interfaces - Default methods - Quiz 14medium