Finally
public class Finally {
public static void main(String[] args) {
int[] a = new int[]{1, 2};
try {
for (int i = 0; i < 3; i++) {
System.out.printlna[i]);
}
} catch (ArrayIndexOutOfBoundsException ex) {
System.out.println(ex);
}
finally{
System.out.println("Inside finally block"); /* A finally block of code always executes,
whether or not an exception has occurred. */
}
}
}
Output:
1
2
java.lang.ArrayIndexOutOfBoundsException: 2
Inside finally block