public class Finally {
public static void main(String[] args) {
new Finally().run();
}
private void run() {
int i;
int a[] = new int[2];
for(i = 0; i <= 2; i++) {
try {
a[i] = 0;
} catch(ArrayIndexOutOfBoundsException e) {
System.out.println("exception: " + e.getMessage());
e.printStackTrace();
} finally {
System.out.println("Gets to finally block (" + i + ")");
}
}
}
}
Finally.java output
Gets to finally block (0)
Gets to finally block (1)
exception: null
java.lang.ArrayIndexOutOfBoundsException
at Finally.run(Finally.java:12)
at Finally.main(Finally.java:3)
Gets to finally block (2)
Tag: Study Code Program Java
No comments:
Post a Comment