如下所示,是一个java笔试题,考察的是抛出异常之后,程序运行结果,但是这里抛出异常,并没有捕获异常,而是通过finally来进行了流程控制处理。
package com.xxx.test;
public class ExceptionFlow {
public static void main(String[] args) {
try {
System.out.println("hello " + func());
} catch (Exception e) {
e.printStackTrace();
}
}
public static int func() {
int a = 0;
for (int i = 0; i < 3; i++) {
try {
throw new RuntimeException("xx");
} finally {
continue;
}
}
return a;
}
}
运行程序,打印结果如下所示:
这里结果有些出人意料,并没有打印异常信息,其实就是try finally遇到了continue,导致异常信息丢失。如果这里,我