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?

1 Answer 1

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.

1
  • Thanks a lot for the help. It's great to learn from knowledgeable people like you :) Apr 7, 2013 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.