【发布时间】:2018-10-17 10:36:36
【问题描述】:
谁能给我一个为什么new Exception()在这里被忽略的原因?
void bar() throws IOException { //no Exception declared, compilator is ok about that. Why?
try{
throw new EOFException();
}
catch(EOFException eofe){
throw new Exception();
}
finally{
throw new IOException();
}
}
【问题讨论】:
-
因为函数无法抛出
EOFException或Exception,因为IOException总是会抢占它们。 -
是的,但是为什么编译器没有抱怨我们没有在方法声明中添加
throws Exception? -
@Oleksandr 如果 finally 块由于原因 S 突然完成,那么 try 语句由于原因 S 突然完成(并且值 V 的抛出被丢弃并忘记)。 ???