@Test
public void testException() {
try {
while (true) {
try {
int i = 0 / 0;
} finally {
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
*最外层的catch能捕获到0/0异常!
@Test
public void testException() {
try {
while (true) {
try {
int i = 0 / 0;
} finally {
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
*这样catch不能捕获到0/0异常,因为当finally中存在控制语句的时候,第二个try传给finally的异常信息会被break覆盖掉,这样导致好像第一个try里面代码执行正常,就不走catch了!