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
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短