码迷,mamicode.com
首页 > 编程语言 > 详细

Java学习----finally块

时间:2016-01-17 17:30:04      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

 

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

 

Java学习----finally块

标签:

原文地址:http://www.cnblogs.com/dragon1013/p/5137388.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!