小编Cha*_*nth的帖子

在java中,如果try和catch都抛出相同的异常并最终返回怎么办?

public class Abc {
    public static void main(String args[]) {
        System.out.println(Abc.method());
    }

    static int method() {
        try {
            throw new Exception();
        }
        catch(Exception e) {
            throw new Exception();
        }
        finally {
            return 4;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么返回值为4?

java exception-handling

4
推荐指数
1
解决办法
5151
查看次数

标签 统计

exception-handling ×1

java ×1