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
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短