一个关于try、catch、finally问题

来源:互联网 发布:剑灵天女完美身材数据 编辑:程序博客网 时间:2024/05/16 06:32
@Testpublic void testException() {    try {        while (true) {            try {                int i = 0 / 0;            } finally {            }        }    } catch (Exception e) {        e.printStackTrace();    }}

*最外层的catch能捕获到0/0异常!

@Testpublic 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了!

0 0