异常被Windows静默抓住,手动如何处理? [英] Exceptions silently caught by Windows, how to handle manually?

查看:151
本文介绍了异常被Windows静默抓住,手动如何处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当消息泵中抛出异常时,我们在Windows中静静地进入异常并允许应用程序继续运行。例如,我们创建了一个测试MFC MDI应用程序,并覆盖了OnDraw:

We're having problems with Windows silently eating exceptions and allowing the application to continue running, when the exception is thrown inside the message pump. For example, we created a test MFC MDI application, and overrode OnDraw:

void CTestView::OnDraw(CDC* /*pDC*/)
{
    *(int*)0 = 0; // Crash

    CTestDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
        return;

    // TODO: add draw code for native data here
}

运行应用程序时,您会发现一个令人讨厌的错误消息,但实际上根本没有什么。该程序似乎运行良好,但如果您检查输出窗口,您将看到:

You would expect a nasty error message when running the application, but you actually get nothing at all. The program appears to be running perfectly well, but if you check the output window you will see:


$ b $的第一次机会异常b 0x13929384在Test.exe中:
0xC0000005:访问冲突写入
位置0x00000000。

Test77中的0x77c6ee42
的第一次异常:0xC0150010:
激活上下文被禁用
对于当前线程
执行不活动。

First-chance exception at 0x13929384 in Test.exe: 0xC0000005: Access violation writing location 0x00000000.
First-chance exception at 0x77c6ee42 in Test.exe: 0xC0150010: The activation context being deactivated is not active for the current thread of execution.

我知道为什么我正在收到应用程序上下文异常,但为什么它会被静默处理?这意味着我们的应用程序在使用时可能会遇到严重的问题,但是我们永远不会知道,因为我们的用户永远不会报告任何问题。

I know why I'm receiving the application context exception, but why is it being handled silently? It means our applications could be suffering serious problems when in use, but we'll never know about it, because our users will never report any problems.

推荐答案

浏览类似的问题后,我偶然发现这个答案:
OpenGL抑制基于MFC对话框的应用程序中的异常

After browsing similar questions I stumbled across this answer: OpenGL suppresses exceptions in MFC dialog-based application


好的,我发现了一些更多信息
关于这个。在我的情况下,它是Windows 7
,安装
KiUserCallbackExceptionHandler作为
异常处理程序,之前调用我的
WndProc并给我执行
控制,这是由
ntdll!KiUserCallbackDispatcher完成的。
怀疑这是微软采取的一项安全性
措施,以防止
入侵SEH。

"Ok, I found out some more information about this. In my case it's windows 7 that installs KiUserCallbackExceptionHandler as exception handler, before calling my WndProc and giving me execution control. This is done by ntdll!KiUserCallbackDispatcher. I suspect that this is a security measure taken by Microsoft to prevent hacking into SEH.

解决方案是包装你的wndproc
(或钩子) proc)with a try / except
frame。

The solution is to wrap your wndproc (or hookproc) with a try/except frame."

我已经向Microsoft提交了一个错误报告,你可以看到他们的回应在这里:

http://connect.microsoft.com/VisualStudio/feedback/details/550944/hardware-exceptions-on-x64-machines-are-silently-caught-in-wndproc - 消息

I've filed a bug report with Microsoft, you can see their response here:
http://connect.microsoft.com/VisualStudio/feedback/details/550944/hardware-exceptions-on-x64-machines-are-silently-caught-in-wndproc-messages

从Microsoft:

From Microsoft:


感谢报告。我发现这是一个Windows问题,
,还有一个热修复可用。请参阅
http://support.microsoft.com/kb/976038 一个修复,你可以安装
如果你愿意。

Thanks for the report. I've found out that this is a Windows issue, and there is a hot fix available. Please see http://support.microsoft.com/kb/976038 for a fix that you can install if you wish.

这篇关于异常被Windows静默抓住,手动如何处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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