您的位置:首页 > 编程语言 > Java开发

Java学习----finally块

2016-01-17 16:20 459 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: