异常的应用

来源:互联网 发布:mac 如何恢复默认dns 编辑:程序博客网 时间:2024/06/06 18:02
public class Test {    public static void main(String[] args){          System.out.println(new Test().test());    }    public int test(){        int a=0;        try{            a=1;            execute();            System.out.println(1);            return a;        }catch(RuntimeException e){            a=2;            System.out.println(2);            return a;        }catch(Exception e){            a=3;            System.out.println(3);            return a;        }finally{            a=4;            System.out.println(4);        }    }    public void execute() throws ArrayIndexOutOfBoundsException{        throw new ArrayIndexOutOfBoundsException();    }}

结果为:2 4 2

0 0
原创粉丝点击