public class Rethrow {
int[] data = new int[2];
public static void main(String[] args) {
new Rethrow().run();
}
private void run() {
try {
run2();
} catch(Exception e) {
System.err.println("catch in run(): " + e);
e.printStackTrace();
}
}
private void run2() throws Exception {
try {
run3();
} catch(Exception e) {
System.err.println("catch in run2(): " + e);
throw e;
}
}
private void run3() throws Exception {
try {
data[2] = 0;
} catch(Exception e) {
System.err.println("catch in run3(): " + e);
throw e;
}
}
}
Rethrow.java output
catch in run3(): java.lang.ArrayIndexOutOfBoundsException
catch in run2(): java.lang.ArrayIndexOutOfBoundsException
catch in run(): java.lang.ArrayIndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
at Rethrow.run3(Rethrow.java:28)
at Rethrow.run2(Rethrow.java:19)
at Rethrow.run(Rethrow.java:10)
at Rethrow.main(Rethrow.java:5)
Tag: Study Code Program Java
No comments:
Post a Comment