-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExceptionDemoSolution.java
46 lines (39 loc) · 1.11 KB
/
ExceptionDemoSolution.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
45
46
import java.util.*;
class ExceptionDemoSolution
{
public static void main(String a[])
{
Scanner sobj = new Scanner(System.in);
int iNo1 = 0, iNo2 = 0, iAns = 0;
System.out.println("Enter first Number");
iNo1 = sobj.nextInt();
System.out.println("Enter second Number");
iNo1 = sobj.nextInt();
try
{
System.out.println("Inside Try Block");
iAns = iNo1 / iNo2;
System.out.println("Division is :"+iAns);
}
catch(ArithmeticException obj)
{
System.out.println("Inside Catch 1");
System.out.println(obj);
}
catch(NullPointerException obj)
{
System.out.println("Inside Catch 2");
System.out.println(obj);
}
catch(Exception obj)
{
System.out.println("Inside Catch 3 ");
System.out.println(obj);
}
finally
{
System.out.println("Inside finally Block");
sobj.close();
}
}
}