【发布时间】:2014-10-14 07:46:35
【问题描述】:
这可能很简单,但我不明白为什么输出是 1 4。第 9 行的 return 语句的功能是什么?
public static void main(String[] args) {
try{
f();
} catch(InterruptedException e){
System.out.println("1");
throw new RuntimeException();
} catch(RuntimeException e){
System.out.println("2");
return; \\ Line 9
} catch(Exception e){
System.out.println("3");
} finally{
System.out.println("4");
}
System.out.println("5");
}
static void f() throws InterruptedException{
throw new InterruptedException("Interrupted");
}
提前致谢。
【问题讨论】:
-
运行时异常没有被捕获,因为没有
try并且第9行没有执行。 -
另外 5 也不会被打印,因为
RuntimeException是一个未经检查的异常,因此在内部被捕获(没有明确的try-catch块)并在System.out.println("5");之前终止程序
标签: java exception exception-handling try-catch