首页 > 编程语言 > 详细

Java学习----finally块

时间:2016-01-17 17:27:55      阅读:164      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!