混合本机/托管可执行文件中的最终托管异常处理程序? [英] Final managed exception handler in a mixed native/managed executable?

查看:129
本文介绍了混合本机/托管可执行文件中的最终托管异常处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用/ clr编译的MFC应用程序,我正在尝试为未捕获的托管异常实现最终处理程序。对于本机异常,覆盖 CWinApp :: ProcessWndProcException 即可。

I have an MFC application compiled with /clr and I'm trying to implement a final handler for otherwise un-caught managed exceptions. For native exceptions, overriding CWinApp::ProcessWndProcException works.

Jeff的 CodeProject文章 Application.ThreadException AppDomain.CurrentDomain.UnhandledException ,不会引发。

The two events suggested in Jeff's CodeProject article,Application.ThreadException and AppDomain.CurrentDomain.UnhandledException, are not raised.

有人可以建议一种方法来提供最终的托管异常处理程序吗?

Can anyone suggest a way to provide a final managed exception handler for a mixed executable?

更新:

似乎这些异常处理程序仅在 Application.Run 或类似的下游触发(有辅助线程风格,不记得它的名称。)如果要真正全局地捕获托管对象,例外,您确实需要安装SEH过滤器。您不会得到 System.Exception ,并且如果您想要一个调用堆栈,则必须使用自己的助行器。

It appears that these exception handlers are only triggered downstream of Application.Run or similar (there's a worker thread flavor, can't remember the name.) If you want to truly globally catch a managed exception you do need to install an SEH filter. You're not going to get a System.Exception and if you want a callstack you're going to have to roll your own walker.

在有关此主题的MSDN论坛问题中,建议在 try ... catch(Exception ^)中覆盖MFC主线程的足够低级别的点。 code>。例如, CWinApp :: Run 。这可能是一个很好的解决方案,但我没有考虑任何性能或稳定性方面的问题。在保释之前,您将有机会使用调用堆栈进行登录,并且可以避免默认的Windows不受约束的异常行为。

In an MSDN forum question on this topic it was suggested to override a sufficiently low-level point of the main MFC thread in a try ... catch (Exception^). For instance, CWinApp::Run. This may be a good solution but I haven't looked at any perf or stability implications. You'll get a chance to log with a call stack before you bail and you can avoid the default windows unahndled exception behavior.

推荐答案

浏览互联网,您会发现需要安装一个过滤器,以获取非托管异常,这些异常将过滤器传递到您的AppDomain。来自 CLR和未处理的异常过滤器

Taking a look around the internets, you'll find that you need to install a filter to get the unmanaged exceptions passing the filters on their way to your AppDomain. From CLR and Unhandled Exception Filters:


CLR依靠SEH未处理的异常过滤器机制来捕获未处理的异常。

The CLR relies on the SEH unhandled exception filter mechanism to catch unhandled exceptions.

这篇关于混合本机/托管可执行文件中的最终托管异常处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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