How To Catch an Exception [C++/CX]

1

I am working on a Windows 8 app (C++). I have used the httpclient class from the Windows 8 samples collection.

inline void CheckHResult(HRESULT hResult)
{
    if (hResult == E_ABORT)
    {
        concurrency::cancel_current_task();
    }
    else if (FAILED(hResult))
    {
        throw Platform::Exception::CreateException(hResult);
    }
}

This function throws an exception when the app is not connected to the internet. I am trying to catch the exception in the following lambda like this.

return completionTask.then([this, stringCallback](tuple<HRESULT, wstring> resultTuple)
{
    try
    {
        CheckHResult(std::get<0>(resultTuple));
    }

    catch(Exception^ ex)
    {

    }

    return std::get<1>(resultTuple);
}); 

But it is still showing an unhandled exception:

First-chance exception at 0x77194B32 in Sample.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x08C7EDF4. HRESULT:0x800C0005
If there is a handler for this exception, the program may be safely continued.

Is there anything I am doing wrong?

windows-8
exception-handling
windows-store-apps
c++-cx
asked on Stack Overflow Apr 7, 2013 by Furqan Khan

1 Answer

2

A first-chance exception does not necessarily indicate a problem with your code, and it's not the same as an uncaught exception.

This (oldish, but still correct) article describes what a first-chance exception really is, just a notification to the debugger that an exception has been thrown, whether it'll be caught later or not.

When an application is being debugged, the debugger gets notified whenever an exception is encountered At this point, the application is suspended and the debugger decides how to handle the exception. The first pass through this mechanism is called a "first chance" exception. Depending on the debugger's configuration, it will either resume the application and pass the exception on or it will leave the application suspended and enter debug mode. If the application handles the exception, it continues to run normally.

answered on Stack Overflow Apr 7, 2013 by Joachim Isaksson • edited Apr 7, 2013 by Joachim Isaksson

User contributions licensed under CC BY-SA 3.0