-
Notifications
You must be signed in to change notification settings - Fork 0
/
senarioExceptionCatch.java
44 lines (40 loc) · 1.44 KB
/
senarioExceptionCatch.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
43
44
package exception_handling;
import java.util.*;
import java.lang.*;
class UserDefinedExceptio extends Exception{
public UserDefinedExceptio(String str)
{
super(str);
}
}
public class senarioExceptionCatch{
public static void main(String []args){
System.out.println("******************* 18BCI0174 Aryan Chandrakar *******************");
Scanner sc=new Scanner(System.in);
System.out.println("[*] Enter a number: ");
int n=sc.nextInt();
if(n<=0){
try{
throw new UserDefinedExceptio("~ Entered number either 0 or negative");
}
catch(UserDefinedExceptio ud){
System.out.println("[-] There's an exception,\n"+ud.getMessage());
}
finally{
System.out.println("[!] Thankyou for using our service.");
}
}
else if(n>50 & n<100){
try{
throw new UserDefinedExceptio("~ Entered number between 50 and 100");
}
catch(UserDefinedExceptio ud){
System.out.println("[-] There's an exception,\n"+ud.getMessage());
}
finally{
System.out.println("[!] Thankyou for using our service.");
}
}
else{System.out.println("[+] No exceptiion found, the entered number was "+n+"\n[!] Thankyou for using our service.");}
}
}