Codeoftrip 2017-07-26 11:40 采纳率: 60%
浏览 654

为什么捕获异常之后的输出语句没有被成功执行呢?

 public class XTException extends Exception {

    public XTException(String msg){
        super(msg);
    }
}
 public class Demo {
    public int div(int a,int b) throws XTException{
        int c = a/b;        
        return c;
    }
}
 public class Test {
    public static void main(String[] args) {
        Demo d = new Demo();
        try {
            System.out.println(d.div(10, 0));
        } catch (XTException e) {
            e.printStackTrace();
        }
        System.out.println("为什么不可以输出这句话?");

    }
}

  • 写回答

2条回答

  • 「已注销」 2017-07-26 13:08
    关注

    public class Test {
    public static void main(String[] args) {
    Demo d = new Demo();
    try {
    System.out.println(d.div(10, 0));
    } catch (XTException e) {
    e.printStackTrace();
    System.out.println("为什么不可以输出这句话?");
    }
    }
    }
    没有放在异常捕捉的范围内,当然不会。就和没有放在for的大括号里不会循环一个道理

    评论

报告相同问题?