未捕获 ExecutionEngineException
我很好奇为什么当我执行下面的代码时没有捕获 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.
考虑将
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions()]
属性添加到执行代码的方法中。Consider adding
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions()]
attribute to the method that your code is executed.