java异常

来源:互联网 发布:mybatis sql注入 like 编辑:程序博客网 时间:2024/06/05 20:15
    public static int getInt(String intStr){
        try{
        return Integer.parseInt(intStr);
         }catch(Exception e){
             throw new NumberFormatException();      //用throw是向上一级抛出异常,让调用它的方法去处理该异常。
         }
        

    }




    public static int getInt(String intStr){
        try{
        return Integer.parseInt(intStr);
         }catch(Exception e){

           e.printStackTrace();

            return     0;  //方法自己捕获异常,并自己处理异常。
         }
        

    }

throw为外面方法捕获异常,其他的为自己捕获异常。



   
1 0
原创粉丝点击