考虑到这一点的代码,我可以绝对肯定的是,finally块总是执行,不管something()是什么?
try {
something();
return success;
}
catch (Exception e) {
return failure;
}
finally {
System.out.println("I don't know if this will get printed out");
}
Run Code Online (Sandbox Code Playgroud) public class Abc {
public static void main(String args[]) {
System.out.println(Abc.method());
}
static int method() {
try {
throw new Exception();
}
catch(Exception e) {
throw new Exception();
}
finally {
return 4;
}
}
}
Run Code Online (Sandbox Code Playgroud)
为什么返回值为4?