-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainEx1.java
More file actions
40 lines (33 loc) · 924 Bytes
/
Copy pathMainEx1.java
File metadata and controls
40 lines (33 loc) · 924 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
34
35
36
37
38
39
40
public class MainEx1
{
public static void main(String[] args)
{
int a[] = new int [5];
System.out.println("Before Exception");
try
{
System.out.println("Inside try block");
//a[2]=100;
a[8] = 100; //jumps to catch body
//int z =5/0;
System.out.println("HI");
System.out.println("Hello");
}
catch(ArithmeticException |NullPointerException ae)
{
System.out.println("AE block");
System.out.println(ae.toString());
}
catch(Exception ex)//class name [Exception] variable name [ex] = reference
{ //ex =object created by jvm
System.out.println("Catch block");
System.out.println(ex.toString()); //system defined function and gets the clas name and returns string
//ex belongs to where it extracts the class name ->String
}
System.out.println("After Exception");
for(int i=0;i<5;i++)
{
System.out.println(i);
}
}
}