0

我曾经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!且未打印未处理的异常?

4

0 回答 0