-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserdefined exception
More file actions
33 lines (33 loc) · 922 Bytes
/
userdefined exception
File metadata and controls
33 lines (33 loc) · 922 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
import java.util.Scanner;
class CatchException extends Exception{
public CatchException(String Message){
super(Message);
}}
class Main {
public static void subclass() throws CatchException{
int age;
Scanner sc=new Scanner(System.in);
System.out.print("enter age:");
age=sc.nextInt();
if(age<15){
throw new CatchException("age id not allowed to vote");
}
}
public static void main(String[] args) {
try{
subclass();
}
catch(CatchException c){
System.out.println(c.getMessage());
}
catch(ArithmeticException e){
System.out.print(e.getMessage());
}
catch(ArrayIndexOutOfBoundsException a){
System.out.print(a.toString());
}
finally{
System.out.println("blocks are executed");
}
}
}