Java中的finally块是什么?
finally块位于try块或catch块之后。无论是否普遍存在Exception,最终的代码块都会永远执行。
示例
public class ExcepTest {
public static void main(String args[]) {
int a[] = new int[2];
try {
System.out.println("访问元素三:" + a[3]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("抛出异常:" + e);
} finally {
a[0] = 6;
System.out.println("First element value: " + a[0]);
System.out.println("The finally statement is executed");
}
}
}输出结果
抛出异常: java.lang.ArrayIndexOutOfBoundsException: 3 First element value: 6 The finally statement is executed
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短