java异常多级捕获

来源:互联网 发布:js 方法重载 编辑:程序博客网 时间:2024/05/16 12:52
public static void main(String[] args){        NoBindingTest n = new NoBindingTest();        try{            n.s();        } catch (Exception e){            System.out.println("s-main()");        }        try{            n.t();        } catch (Exception e){            System.out.println("t-main()");        }        try{            n.t2();        } catch (Exception e){            System.out.println("t2-main()");        }    }    public void s(){        try{            int s = Integer.parseInt("s");            System.out.println(s);        } catch (NumberFormatException e){            System.out.println("s()");        }    }    public void t(){        int t = Integer.parseInt("t");        System.out.println(t);    }    public void t2() throws NumberFormatException{        int t2 = Integer.parseInt("t2");        System.out.println(t2);    }


结果:


0 0
原创粉丝点击