Exception Handling in Offline


  • create_task(StorageApplicationPermissions::FutureAccessList->GetFileAsync(token)).then([=](task<StorageFile^> task2)
    	StorageFile^ file;
    	try {
    		file = task2.get();
    	} catch (Platform::InvalidArgumentException^ ex) {

    Above is my code clip to access a remote StorageFile. The problem is that when the network was disconnected, the app will wait several seconds to crash. There is no problem in online. I found that task2 caused exception with its _MP_IMP pointer as nullptr. So I added the try/catch but app was still crashed after several seconds. What is wrong?

    What is the behavior of a task to handle network connection?

    Charlie Chang L

    Thursday, September 27, 2012 9:02 PM

All replies

  • Hi 

    Charlie C

    You should  disable flowing option when a pop-up window is thrown in Visual Stdio.

    Break when this exception type is thrown

    Now execution will not terminated and execute your code inside the catch block.

    Friday, September 28, 2012 2:30 AM
  • Mokarrom,

    Unfortunately that is not a solution. There is still Unhandled exception at 0x739E8AE3 (msvcr110d.dll) in myapp.exe: An invalid parameter was passed to a function that considers invalid parameters fatal. When I click Continue button the error message box will appear again.

    It is an exception in the Win8 Runtime Library I may not be able to handle it. 

    I know that one of a pointer of task2 is nullptr but I can not handle or detect it in my C++ code.  

    Charlie Chang L

    Friday, September 28, 2012 2:14 PM
  • I have Similar problem when I used Web Auth API.

    I had changed the code, and the exception could be in control. The code is base Web auth API, but it may help to you.

    auto LoginOp = WebAuthenticationBroker::AuthenticateAsync(WebAuthenticationOptions::UseTitle,
       startURI, endURI);
      LoginOp->Completed = ref new AsyncOperationCompletedHandler<WebAuthenticationResult^>([this](
       IAsyncOperation<WebAuthenticationResult^>^ a, AsyncStatus b)
        if(a!= nullptr)
         WebAuthenticationResult^ result = a->GetResults();
         if (result->ResponseStatus == WebAuthenticationStatus::Success)
          //bLogin = true;
          // do something
       }catch(Exception^ ex)
        OutputDebugString( ex->Message->Data() );

    Wednesday, October 17, 2012 6:50 AM
  • Thanks Tony.

    Finally I found a general solution to capture any exceptions of network or file processing. I need to define a new function to replace the original async operation. Here is the sample code:

    IAsyncOperation<StorageFile^>^ OpenAnyFileAsync(Uri^ uri)


    try {

    return Windows::Storage::StorageFile::GetFileFromApplicationUriAsync(uri);

    } catch (Platform::Exception^ ex) {

    ; // return your exception processing function



    create_task( OpenAnyFileAsync(Uri^ uri) ).then([=]( StorageFile^ file )


    // my code


    Charlie Chang L

    • Edited by Charlie C Wednesday, October 17, 2012 3:52 PM
    Wednesday, October 17, 2012 3:47 PM
  • your original code caught invalid argument exception, that is not the exception type that will occur in this case. (although the debugger error message indicates this, I assume the source of confusion).

    your fixed version works because you catch all exceptions (using Platform::Exception). if you convert your original code to have the same catch it will work as well.


    Thursday, October 18, 2012 6:33 AM
  • Platform::Exception can not catch "all" exceptions. I tested both methods. My solution can capture some exceptions that will cause crash for the last task-chain catch. In my original code even I change the catch to Platform::Exception, it can not catch the nullptr inside the task. It may be a bug or something wrong. I think it is better to catch an exception and handle it instantly than transfer exception to an exception chain.

    Charlie Chang L

    Thursday, October 18, 2012 6:17 PM