小编kau*_*nha的帖子

使用finally的java中的异常处理

public class CheckProg {
    public int math(int i) {
        try {
            int result = i / 0;
       // throw new IOException("in here");
        } catch (Exception e) {
            return 10;
        } finally {
            return 11;
        }
    }
    public static void main(String[] args) {
        CheckProg c1 = new CheckProg();
        int res = c1.math(10);
        System.out.println("Output :" + res);
   }
Run Code Online (Sandbox Code Playgroud)

问:如果我运行上面的代码,我得到的结果为输出:11

为什么?不应该在catch块之前捕获异常并返回吗?

java exception-handling exception

5
推荐指数
1
解决办法
91
查看次数

标签 统计

exception ×1

exception-handling ×1

java ×1