-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNestedTryCatchExample.java
More file actions
39 lines (35 loc) · 1.13 KB
/
Copy pathNestedTryCatchExample.java
File metadata and controls
39 lines (35 loc) · 1.13 KB
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
public class NestedTryCatchExample {
public static void main(String args[]) {
// outer try block
try {
// inner try block 1
try {
System.out.println("going to divide by 0");
int b = 39 / 0;
}
// catch block of inner try block 1
catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e);
}
// inner try block 2
try {
int a[] = new int[5];
// assigning the value out of array bounds
a[4] = 4;
System.out.println("other statement");
}
// catch block of inner try block 2
catch (ArithmeticException e) {
System.out.println(e);
}
System.out.println("other statement");
}
// catch block of outer try block
catch (Exception e) {
System.out.println("handled the exception (outer catch)");
} finally {
System.out.println("Finally");
}
System.out.println("normal flow..");
}
}