如果你把从catch块异常时最终运行? [英] When is finally run if you throw an exception from the catch block?
本文介绍了如果你把从catch块异常时最终运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
try {
// Do stuff
}
catch (Exception e) {
throw;
}
finally {
// Clean up
}
在上面的块时,finally块叫什么? e的投掷前或最后调用,再搭上?
In the above block when is the finally block called? Before the throwing of e or is finally called and then catch?
推荐答案
这将是e的重新抛出之后调用(即在执行catch块之后)
It would be called after e is re-thrown (i.e. after the catch block is executed)
编辑这款7年后的今天 - 一个重要的说明是,如果电子
不是由try / catch块捕获进一步调用堆栈或一个全局异常处理程序处理,那么最后
块的可能的根本就不会执行。
editing this 7 years later - one important note is that if e
is not caught by a try/catch block further up the call stack or handled by a global exception handler, then the finally
block may never execute at all.
这篇关于如果你把从catch块异常时最终运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文