考虑到这段代码,我是否可以绝对确定该finally块始终执行,无论something()是什么?
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"); }
是的,finally将在try或catch代码块执行后调用。
try
catch
唯一finally不会被调用的时间是:
System.exit()
Runtime.getRuntime().halt(exitStatus)
kill -9 <pid>