-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExceptionClass.java
42 lines (35 loc) · 1.11 KB
/
ExceptionClass.java
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
//TWENTIETH PROGRAM OF JAVA PRACTICAL
import java.util.Scanner;
class ExceptionExtends extends Exception{
public ExceptionExtends(String h){
System.out.println(h);
}
public ExceptionExtends(){
System.out.println("ExceptionExtends.lang.exception:"+this);
}
}
public class ExceptionClass {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
try{
System.out.print("Enter the id :");
int a=sc.nextInt();
if(a==0){
throw new ExceptionExtends("Error as default values cannot be used!");
}
else if(a<0){
throw new ExceptionExtends("Error as id cannot be negative!");
}
else if(a==8){
throw new ExceptionExtends();
}
System.out.println("Thanks for entering your information,have a nice day");
}
catch(ExceptionExtends e){
System.out.println("Try Again!");
}
finally{
sc.close();
}
}
}