C#终结引发异常? [英] c# finalizer throwing exception?

查看:110
本文介绍了C#终结引发异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从MSDN报价:

如果敲定或敲定的覆盖抛出一个异常,运行时会忽略异常,终止该Finalize方法,并继续最终处理。

If Finalize or an override of Finalize throws an exception, the runtime ignores the exception, terminates that Finalize method, and continues the finalization process.

然而,如果我有:

~Person()
{
throw new Exception("meh");
}



然后它会导致运行时异常?

then it results in a runtime exception?

PS我知道,这是不可能发生的,但我只是解决此问题好奇。我们的一个客户有身边全是其终结的空尝试捕捉..它甚至没有登录时,事情发生了错误或reserect对象:/

p.s. I know that this should never happen, however I'm just curious around this behaviour. One of our clients had an empty try catch around all of their finalizers.. it didn't even log when things went wrong or reserect the object :/

推荐答案

将您报价的来源是非常重要的。我必须假设它谈论一个老版本的.NET,也许1.x版本。它试图将未处理的异常的宽容,吞咽他们没有吱吱声。没有工作顺利,代码块默默失败是非常难以调试。

Linking the source of your quote is important. I have to assume it talks about an old version of .NET, perhaps version 1.x. It tried to be "tolerant" of unhandled exceptions, swallowing them without a squeak. That did not work out well, chunks of code silently failing is extraordinarily hard to debug.

在.NET 2.0版本杜绝的是,默认的CLR主机终止应用任何未处理的异常。在终结一个例外是致命的。

The .NET 2.0 version put an end to that, the default CLR host terminates the app for any unhandled exception. An exception in a finalizer is fatal.

这篇关于C#终结引发异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆