问题描述
另外一个面试问题,这是期待一个真/假答案,我也不太清楚。
Another interview question which was expecting a true / false answer and I wasn't too sure.
- http://stackoverflow.com/questions/582095/in-net-what-if-something-fails-in-the-catch-block-will-finally-always-get-call
- http://stackoverflow.com/questions/464098/does-a-finally-block-always-run
- http://stackoverflow.com/questions/111597/conditions-when-finally-does-not-execute-in-a-net-try-finally-block
- <一个href="http://stackoverflow.com/questions/345091/will-$c$c-in-a-finally-statement-fire-if-i-return-a-value-in-a-try-block">http://stackoverflow.com/questions/345091/will-$c$c-in-a-finally-statement-fire-if-i-return-a-value-in-a-try-block
- http://stackoverflow.com/questions/582095/in-net-what-if-something-fails-in-the-catch-block-will-finally-always-get-call
- http://stackoverflow.com/questions/464098/does-a-finally-block-always-run
- http://stackoverflow.com/questions/111597/conditions-when-finally-does-not-execute-in-a-net-try-finally-block
- http://stackoverflow.com/questions/345091/will-code-in-a-finally-statement-fire-if-i-return-a-value-in-a-try-block
推荐答案
最后
执行大多数时间。这是几乎所有情况下。例如,如果一个异步异常(如 StackOverflowException
, OutOfMemoryException异常
, ThreadAbortException
)被抛出的线程上,最后
执行是得不到保障。这是写高度可靠的code 的存在,为什么约束的执行区。
finally
is executed most of the time. It's almost all cases. For instance, if an async exception (like StackOverflowException
, OutOfMemoryException
, ThreadAbortException
) is thrown on the thread, finally
execution is not guaranteed. This is why constrained execution regions exist for writing highly reliable code.
有关采访的目的,我希望这个问题的答案是假(我不会保证任何东西!面试官可能不知道这一点她自己!)。
For interview purposes, I expect the answer to this question to be false (I won't guarantee anything! The interviewer might not know this herself!).
这篇关于在C#将finally块在try执行,抓,最后如果未处理的异常被抛出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!