019-002-004

Exception Classes: Custom Exception

Hard

Problem Description

Custom Exception Classes

In this problem, you will create a program that defines a custom exception class by extending the Exception class, throws and catches the exception based on specific business logic conditions, and displays the result to standard output.

Create custom exceptions by extending Exception class. Enables business logic-specific exception handling.

Test Cases

※ Output examples follow programming industry standards

Normal case
Input:
25
Expected Output:
Valid age: 25
Error case
Input:
-5
Expected Output:
Error: Invalid age - must be between 0 and 150
Boundary case
Input:
0
Expected Output:
Valid age: 0
Error case
Input:
200
Expected Output:
Error: Invalid age - must be between 0 and 150

Your Solution

Current Mode: My Code
InvalidAgeException.java🔒
Solution.java🔒
2/6 ファイル126B
⚠️警告
  • No main method found
import java.util.Scanner;

class InvalidAgeException extends Exception {
}
0 B / 5 MB

You have 10 free executions remaining