package Exception;
public class exception4 {
public exception4() {
}
boolean testEx() throws Exception {
boolean ret = true;
try {
ret = testEx1();
} catch (Exception e) {
System.out.println("testEx, catch exception");
ret = false;
throw e;
} finally {
System.out.println("testEx, finally; return value=" + ret);
return ret;
}
}
boolean testEx1() throws Exception {
boolean ret = true;
try {
ret = testEx2();
if (!ret) {
return false;
}
System.out.println("testEx1, at the end of try");
return ret;
} catch (Exception e) {
System.out.println("testEx1, catch exception");
ret = false;
throw e;
} finally {
System.out.println("testEx1, finally; return value=" + ret);
return ret;
}
}
boolean testEx2() throws Exception {
boolean ret = true;
try {
int b = 12;
int c;
for (int i = 2; i >= -2; i--) {
c = b / i;
System.out.println("i=" + i);
}
return true;
} catch (Exception e) {
System.out.println("testEx2, catch exception");
ret = false;
throw e;
} finally {
System.out.println("testEx2, finally; return value=" + ret);
return ret;
}
}
public static void main(String[] args) {
exception4 testException1 = new exception4();
try {
testException1.testEx();
} catch (Exception e) {
e.printStackTrace();
}
}
}
这是我在学习异常这部分知识时 看到一位博主的文章中举出的例子 这段代码的输出结果是
i=2
i=1
testEx2, catch exception
testEx2, finally; return value=false
testEx1, finally; return value=false
testEx, finally; return value=false
我的问题是testEx2方法的catch块中通过throw e;抛出了异常,为什么在testEx1方法中这个异常没有被textEx1方法中的catch块捕获并输出相应语句,这个异常去哪里了呢?帮忙解答一下疑问,感激不尽!