- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExceptionHandling2.java
More file actions
Latest commit
28 lines (28 loc) · 623 Bytes
/
Copy pathExceptionHandling2.java
File metadata and controls
28 lines (28 loc) · 623 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
importjava.util.*;
classAgeExceptionextendsException{
publicAgeException(Stringmsg){
super(msg);
}
}
classExceptionHandling2{
privatestaticvoidverifyAge(intage) throwsAgeException{
if(age<18){
thrownewAgeException("You can not vote");
}else{
System.out.println("you can vote");
}
}
publicstaticvoidmain(String[] args){
Scannersc = newScanner(System.in);
System.out.println("Enter your age : ");
intage = sc.nextInt();
try{
verifyAge(age);
}catch(AgeExceptione){
System.out.println(e);
}
finally{
System.out.println("I am finally and i always run...");
}
}
}