如果finally块抛出异常会怎么样? [英] What happens if a finally block throws an exception?
问题描述
如果finally块抛出异常,那么是否完全发生?
If a finally block throws an exception, what exactly happens?
具体来说,如果异常通过finally块中途抛出,会发生什么。在这个块中执行其余的语句(之后)是否被调用?
Specifically, what happens if the exception is thrown midway through a finally block. Do the rest of statements (after) in this block get invoked?
我知道异常会向上传播。
I am aware that exceptions will propagate upwards.
推荐答案
如果finally块抛出一个异常,那么完全
该异常传播出来,并且(可以)在更高级别处理。
That exception propagates out and up, and will (can) be handled at a higher level.
您的最终版块将不会完成超出抛出异常的点。
Your finally block will not be completed beyond the point where the exception is thrown.
如果finally块在处理较早的异常时正在执行,则该第一个异常丢失。
If the finally block was executing during the handling of an earlier exception then that first exception is lost.
C#4语言规范& 8.9.5:如果finally块抛出另一个异常,则终止当前异常的处理。
C# 4 Language Specification § 8.9.5: If the finally block throws another exception, processing of the current exception is terminated.
这篇关于如果finally块抛出异常会怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!