异常执行的顺序

来源:互联网 发布:gcp网络培训入口 编辑:程序博客网 时间:2024/05/21 17:59
package cn.exp;//输出结果为BCD//因为throw  new Exception();即抛出了异常所以会跳跃到catch,System.out.println("A");不会执行。//但是在此之前func()里的finally是要执行的。class Test1{public static void func()throws Exception{try{throw  new Exception();}finally{System.out.println("B");}}public static void main(String[] args){try{func();System.out.println("A");}catch(Exception e){System.out.println("C");}System.out.println("D");}}