【发布时间】:2015-08-11 08:05:36
【问题描述】:
class TestExceptions {
public static void main(String[] args) throws Exception {
try {
System.out.println("try");
throw new Exception();
} catch(Exception e) {
System.out.println("catch");
throw new RuntimeException();
} finally {
System.out.println("finally");
}
}
}
以下是我尝试在 Eclipse 中多次运行代码时的输出。到目前为止,我相信每当 try/catch 块中的最后一行代码即将被执行(可能是返回或抛出新的 Exception() 类型的 stmt),finally 块都会被执行,但这里的输出不同每次?谁能澄清我的假设是对还是错?
try
catch
Exception in thread "main" finally
java.lang.RuntimeException
at TestExceptions.main(TestExceptions.java:9)
Exception in thread "main" try
catch
java.lang.RuntimeException
at TestExceptions.main(TestExceptions.java:9)
finally
【问题讨论】: