forked from akash-coded/C133-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinallyExample.java
More file actions
25 lines (25 loc) · 1007 Bytes
/
FinallyExample.java
File metadata and controls
25 lines (25 loc) · 1007 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
public class FinallyExample {
public static void main(String[] args) {
int[] a = { 10, 20, 30 };
try {
System.out.println("Before exception");
System.out.println(a[4]);
System.out.println("After exception");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Exception caught and handled");
} finally {
System.out.println("Inside finally block");
}
System.out.println("Normal execution");
try {
System.out.println("Before exception in 2nd try block");
System.out.println(a[1] / 0);
System.out.println("After exception in 2nd try block");
} catch (ArithmeticException e) {
System.out.println("Exception caught and handled in 2nd catch block");
} finally {
System.out.println("Inside 2nd finally block");
}
System.out.println("Normal execution after 2nd try-catch-finally");
}
}