美文网首页
java finally语句中使用return时

java finally语句中使用return时

作者: 扎哈_ | 来源:发表于2019-08-23 14:37 被阅读0次
    public static String test() {
        try {
            throw new RuntimeException("???");
        } catch (RuntimeException e) {
            throw new RuntimeException("!!!");
        } finally {
            System.out.println("111");
            return "";
        }
    }

如上例,当我试图让调用者处理这个RuntimeException时,这个RuntimeException就消失了,原因是在finally语句中执行了return。导致异常消失了。

相关文章

网友评论

      本文标题:java finally语句中使用return时

      本文链接:https://www.haomeiwen.com/subject/vaxtectx.html