019-002-012
Exception Hierarchy
Medium
Problem Description
Exception Hierarchy
In this problem: You will understand the difference between checked and unchecked exceptions by creating AppException (checked) and AppRuntimeException (unchecked) custom exceptions.
Learning Objective: Understand the hierarchy and usage of checked vs unchecked exceptions
Overview
Java exceptions are divided into Exception (checked) and RuntimeException (unchecked). Checked exceptions require throws declaration and catch handling, while unchecked exceptions do not.
Specifications
AppExceptionextendsException: checked exceptionAppRuntimeExceptionextendsRuntimeException: unchecked exceptionServiceclass:checkedMethod(): throwsAppException("Checked error occurred")(throws declaration required)uncheckedMethod(): throwsAppRuntimeException("Unchecked error occurred")
- In Main, handle both with try-catch and output exception type name and message
Output Format
Caught checked: AppException: Checked error occurred
Caught unchecked: AppRuntimeException: Unchecked error occurred
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up