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 关于健康的祝福语简短
18 新年导员祝福语简短