Java - Custom ExceptionsWhich Java class should a custom checked exception extend?AExceptionBRuntimeExceptionCErrorDThrowableCheck Answer
Step-by-Step SolutionSolution:Step 1: Recall checked vs unchecked exceptionsChecked exceptions must be declared or handled and extend Exception but not RuntimeException.Step 2: Identify correct superclass for checked exceptionsException is the base class for checked exceptions; RuntimeException is for unchecked.Final Answer:Exception -> Option AQuick Check:Checked exception base class = Exception [OK]Quick Trick: Checked exceptions extend Exception, unchecked extend RuntimeException [OK]Common Mistakes:Extending RuntimeException for checked exceptionsExtending Error which is for serious JVM errorsExtending Throwable directly without reason
Master "Custom Exceptions" in Java9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Java Quizzes Abstraction - Abstract classes - Quiz 7medium Classes and Objects - Object creation - Quiz 1easy Custom Exceptions - Why custom exceptions are needed - Quiz 12easy Encapsulation - Private data members - Quiz 8hard Exception Handling - Checked vs unchecked exceptions - Quiz 8hard Inheritance - Super keyword - Quiz 1easy Inheritance - Super keyword - Quiz 8hard Interfaces - Why interfaces are used - Quiz 3easy Object-Oriented Programming Concepts - OOP principles overview - Quiz 2easy Polymorphism - Upcasting and downcasting - Quiz 9hard