When create_task throws exception I cannot catch it in try-catch block

0

I try to receive user's PushNotification Channel URI (Windows 10 platform) and for some users application generate exception This operation returned because the timeout.

To handle errors in a task chain I should add a task-based continuation at the end of the chain and handle all errors there (as explained here https://docs.microsoft.com/en-us/windows/uwp/threading-async/asynchronous-programming-in-cpp-universal-windows-platform-apps#handling-errors-in-a-task-chain).

So I did that. But after I call t.get(); system generate Platform::COMException^ exception by it not catch in try-catch block. Why?

There is the code:

{
    create_task(PushNotificationChannelManager::CreatePushNotificationChannelForApplicationAsync())
    .then([this](PushNotificationChannel^ pnChannel)
    {
        // ..
        // DONE: pnChannel->Uri
        // ..
    }, task_continuation_context::get_current_winrt_context())
    .then([](task<void> t)
    {
        try
        {
            t.get(); // <<<< After exec this line app crash!
        }
        catch (Platform::COMException^ e)
        {
            OutputDebugString(L"Exception catches!");
        }
    });
}

There is the full exception message:

Exception thrown at 0x00007FFD9D74A388 in GameName.exe: Microsoft C++
exception: Platform::COMException ^ at memory location 0x000000249A9FEB60. 
HRESULT:0x800705B4 This operation returned because the timeout period expired.
WinRT information: This operation returned because the timeout

And Visual Studio throws me to the file c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\exception to block:

[[noreturn]] void _RethrowException() const
    {
    __ExceptionPtrRethrow(this); // <<<< here everything stoped!
    }

UPDATED:

Enviroment:

  • Visual Studio 2017 (15.7.3)
  • Project based on cocos2d-x (3.16)
  • Project Targe Platform Version = 10.0.1493.0
  • Project Platform Toolset = Visual Studio 2015 (v140)

You can clone cocos2dx project and in MainScene paste code I showed before in onEnter method (or anywhere).

I got a situation when I had crash 100% for me

  1. Uninstall app if it was built before;
  2. Disconnect from the internet;
  3. Build app & launch;
  4. The app will try to detect Channel URI & will crash (but with crash message = WinRT information: The network is not present or not started).

I understand that throwing that exception is normal. But I still cannot understand why when I call t.get() it not catch exception Platform::COMException^

push-notification
uwp
c++-cli
wns
asked on Stack Overflow Jun 25, 2018 by Andrei Bakulin • edited Jun 27, 2018 by Andrei Bakulin

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0