我一直在追踪工作中一个非常阴险的错误.似乎导致我一直在跟踪的非常奇怪的行为的事件似乎是在处理计时器回调时抛出的异常.异常不是由我的任何代码处理的,因此我希望调试器会收到未处理异常的通知,并提醒我一个不错的弹出窗口.不,相反,"第一次机会"异常消息会追溯到调试器,并且所有内容都会静默移动.
我写了以下程序来演示这个问题:
#include "stdafx.h"
#include <Windows.h>
class FooExcept
{
};
VOID CALLBACK Timer(HWND hwnd,
UINT uMsg,
UINT_PTR idEvent,
DWORD dwTime)
{
printf("Here\n");
throw FooExcept();
printf("Also Here\n");
}
int _tmain(int argc, _TCHAR* argv[])
{
SetTimer(0, 0, 1000, Timer);
int bRet;
HWND hWnd;
MSG msg;
// Standard Win32 message pump
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return …Run Code Online (Sandbox Code Playgroud)