-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomException1
More file actions
68 lines (36 loc) · 745 Bytes
/
Copy pathCustomException1
File metadata and controls
68 lines (36 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.util.Scanner;
class AgeException extends Exception
{
public AgeException(String message)
{
super(message);
}
}
public class CustomException1
{
public static void validateAge(int age)throws AgeException
{
if(age<18)
{
throw new AgeException("Age must be atleast 18 years old");
}
System.out.println("Age is valid: "+age);
}
public static void main(String args[])
{
Scanner scanner=new Scanner(System.in);
System.out.println("Enter your age: ");
int age=scanner.nextInt();
try
{
validateAge(age);
}
catch(AgeException e)
{
System.out.println("Error: "+e.getMessage());
}
finally {
System.out.println("I'm finally block,End of the program");
}
}
}