Java学习----finally块

 

public class Test {
    
    String x;
    public static void main(String[] args) {
        
        Test test = new Test();
        try {
            System.out.println(5/0);
        } catch (ArrayIndexOutOfBoundsException e) {
            test.x = "hello world";
            System.out.println(test.x.length());
        } catch (NullPointerException e) {
            // TODO: handle exception
            test.x = "hello world";
            System.out.println(test.x.length());
        } catch (Exception e) { // 必须放到最后
            // TODO: handle exception
            e.printStackTrace();
        }finally {
            System.out.println("finally");
        }
        
        System.out.println("end");
    }
}
java.lang.ArithmeticException: / by zero
    at com.demo.pkg5.Test.main(Test.java:10)
finally
end

 

posted @ 2016-01-17 16:20  Dragon&Hmm  阅读(103)  评论(0编辑  收藏  举报