即使连接到 UnhandledExceptionHandler,您的应用程序也已停止工作
我通过挂钩 UnhandledExceptionHandler 事件,在 AppDomain 级别向我的 C# 应用程序添加了一个全局错误处理程序。
我的问题是,即使我正在处理这个异常,我仍然收到弹出窗口说“应用程序已停止工作”。
这是正常行为吗?可以关掉吗?或者也许实际显示此消息是一个好习惯?
I have added a global error handler at the AppDomain level to my C# application, by hooking into the UnhandledExceptionHandler event.
My problem is, that even though i am handling this exception, i still get the popup saying "App has stopped working".
Is this normal behaviour? Can it be turned off? or maybe it is good practice to actually have this message displayed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。想一想,您的代码应该在哪里恢复?处于什么状态?
仅通过在程序中的适当位置(即顶层代码)处理异常。 UnhandledExceptionHandler 不是替代品,而是不完整处理的诊断工具。
是的。您应该记录到达那里的异常,但您已经失去了控制。
Yes. Think about it, where should your code be resumed? In what state?
Only by handling exceptions a the appropriate point in your program, ie in the toplevel code. The UnhandledExceptionHandler is not a replacement but a diagnosis-tool for incomplete handling.
Yes. You should log exceptions that arrive there but you've already lost control.
我认为当你到达那个点时不可能恢复应用程序的现有实例。 MSDN 没有相关信息,并建议“如果有足够的有关应用程序状态的信息,则可以采取其他操作 - 例如保存程序数据以供以后恢复。” (链接)
不这样做是有道理的能够恢复。如果您在 Unhandled ExceptionHandler 中捕获异常,则意味着您的应用程序无法处理该异常,因此这是您记录发生的情况(以供以后调查)或保存用户数据的最后机会。如果“未处理的”异常处理程序必须“处理”异常并恢复应用程序,这听起来像是一个架构问题。
为什么不通过创建应用程序的新实例来恢复? (或使用 重启和恢复功能)
I don't think is possible to recover the existing instance of an app when you get at that point. MSDN has no information about it and is suggested " If sufficient information about the state of the application is available, other actions may be undertaken — such as saving program data for later recovery." (link)
It kind of makes sense to not be able to recover. If you catch an exception in the Unhandled ExceptionHandler it means that your application was not able to deal with it so is your last chance to log what happened (for later investigations) or save the user's data. It sounds like an architecture problem if the "unhandled" exception handler must "handle" exceptions and recover the app.
Why not recover by creating a new instance of the app? (or by using the Restart and Recovery feature)