当我运行以下代码时,有两个结果。
package scjp;
public class ExceptionTest {
public static void main(String[] args) {
ExceptionTest test = new ExceptionTest();
test.method1();
}
public void method1() {
try {
System.out.println("Try Block");
if (!true) {
return;
} else {
throw new RuntimeException();
}
}finally {
System.out.println("Finally Block");
}
}
}
一个结果是
Try Block
Exception in thread "main" java.lang.RuntimeException
at scjp.ExceptionTest.method1(ExceptionTest.java:17)
at scjp.ExceptionTest.main(ExceptionTest.java:7)
Finally Block
和另一个,
Try Block
Finally Block
Exception in thread "main" java.lang.RuntimeException
at scjp.ExceptionTest.method1(ExceptionTest.java:17)
at scjp.ExceptionTest.main(ExceptionTest.java:7)
每次我运行上述代码时,答案都会发生变化。据我了解,它应该始终是相同的结果。你能帮我什么吗???