使用了SetUnhandledExceptionFilter但未调用相应的方法

时间:2013-04-15 13:06:05

标签: c++ winapi exception

我使用SetUnhandledExceptionFilter来安装自定义异常处理程序。在下面的代码中,我希望如果发生未处理的异常,则调用UnhandledException方法并打印foo!

namespace mcFastNative {

Receiver* incOrdersA;
IncFeed* incOrders;

Receiver* snpOrdersA;
SnapshotFeed* snpOrders;

    // not important methods are ommited

bool McFastNativeAdapter::Disconnect() {
    incOrdersA->Disconnect();
    return true;
}


LONG WINAPI UnhandledException(LPEXCEPTION_POINTERS ExceptionInfo)  
{  
    printf("foo!");
            return EXCEPTION_CONTINUE_SEARCH;
}

void McFastNativeAdapter::Initialize(unsigned long feedA_group, unsigned long feedA_source, int feedA_port,
    unsigned long historicalIp, int historicalPort,
    unsigned long snapshotGroup, unsigned long snapshotSource, int snapshotPort)
{
    // Init WinSock
    WSAData data;
    WSAStartup( MAKEWORD( 2, 2 ), &data );

    SetUnhandledExceptionFilter(UnhandledException);

    incOrdersA = new Receiver(feedA_group, feedA_source, feedA_port);
    snpOrdersA = new Receiver(snapshotGroup, snapshotSource, snapshotPort);

    incOrders = new IncFeed("IncFeed");
    incOrdersA->SetFeed(incOrders);

    snpOrders = new SnapshotFeed("SnapshotFeed");
    snpOrdersA->SetFeed(snpOrders);
}

}

但我收到了这样的结果:

System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception. at mcFastNative.McFastNativeAdapter.Disconnect() at Fast.mcFastAdapterCpp.Disconnect() ...

foo!未打印到控制台,因为您可以看到发生异常。为什么incOrdersA->Disconnect();中未处理的异常未被捕获且foo!未被打印?

0 个答案:

没有答案