未捕获 ExecutionEngineException

发布于 2024-10-18 00:06:53 字数 549 浏览 9 评论 0原文

我很好奇为什么当我执行下面的代码时没有捕获 ExecutionEngineException 。

try                            
{
   ((Window)window).Close();
}
catch (Exception e)
{
   Console.WriteLine(e);
}

永远不会到达 WriteLine。有什么想法如何捕获这个异常吗?

注意:我知道当 DockablePanes 之一处于自动隐藏模式且可见并且用户尝试关闭 wpf 窗口时,AvalonDock 会引发异常。

更新: 我已阅读备注部分:

CLR 永远不会以托管代码可以捕获它的方式抛出此异常。

所以问题是如何在类似的事情之后很好地关闭应用程序。

I am curious why ExecutionEngineException is not caught when I am executing the code below.

try                            
{
   ((Window)window).Close();
}
catch (Exception e)
{
   Console.WriteLine(e);
}

The WriteLine will never be reached. Any ideas how to catch this exception ?

Note: I know the exception is thrown by AvalonDock when one of DockablePanes is in AutoHide mode, is visible and user is trying to close wpf window.

Update:
I've read the remarks section on msdn regarding this exception:

The CLR never throws this exception in such a way that managed code can catch it.

So the question is how to close application nicely after something like that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吹泡泡o 2024-10-25 00:06:53

ExecutionEngineException 表示致命错误,您不应尝试恢复或处理该错误。你需要在问题发生之前从根源上解决这个问题,而不是试图优雅地处理它。

既然您说您已经知道问题的根源,您应该采取措施防止应用程序达到被迫抛出致命异常的状态。

The ExecutionEngineException represents a fatal error from which you should not try to recover or handle. You need to tackle this at the source of the problem before it happens and not try to handle it gracefully.

Since you say you already know the source of the problem you should take actions to prevent the application to reach the state where its forced to throw the fatal exception.

一个人的旅程 2024-10-25 00:06:53

考虑将 [System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions()] 属性添加到执行代码的方法中。

Consider adding [System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions()] attribute to the method that your code is executed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文