异常注意事项

  • try   catch  finally return
  • public  int  f(){
        try{
            String demo=null;
            demo.split("a");
            System.out.println("try");                
        }catch(Exception e){        
            System.out.println("catch");               
        }finally{    
            System.out.println("finally");               
        }
    }  
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            haha a=new haha();
            a.f();
        }
    }

     

  • catch 不能独立于 try 存在。
  • 在 try/catch 后面添加 finally 块并非强制性要求的。
  • try 代码后不能既没 catch 块也没 finally 块。
  • try, catch, finally 块之间不能添加任何代码
posted @ 2017-06-27 18:05  冰逸101  阅读(183)  评论(0编辑  收藏  举报