我知道,finally块来执行,即使代码抛出异常,也成功完成,现在我的疑问是这样的代码请问这个代码工作中的Java内部处理
收益40
这是显而易见的,但现在如果我
评论返回40;
返回10
任何人可以帮助我了解如何JVM返回10为什么不抱怨说,函数应该返回一个值。后try
和catch
块
public class ExceptionTest {
public static void main(String[] args) {
int i= returnSomething();
System.out.println(i);
}
private static int returnSomething() {
try{
System.out.println("try");
return 10;
}
catch(Exception e)
{
return 20;
}
finally
{
System.out.println("finally ");
return 40;
}
}
}
你可以看看这个[问题](http://programmers.stackexchange.com/q/188858)。它可能会清除你所有的疑惑! – SudoRahul
http://stackoverflow.com/questions/15616984/return-statement-in-java-exception-handling – VAr