当create_task引发异常时,我无法在try-catch块中捕获它

时间:2018-06-25 17:49:00

标签: push-notification uwp c++-cli wns

我尝试接收用户的PushNotification Channel URI(Windows 10平台),并为某些用户应用程序生成异常This operation returned because the timeout

要处理任务链中的错误,我应该在链的末尾添加一个基于任务的延续,并在那里处理所有错误(如此处https://docs.microsoft.com/en-us/windows/uwp/threading-async/asynchronous-programming-in-cpp-universal-windows-platform-apps#handling-errors-in-a-task-chain所述)。

所以我做到了。但是,在我调用t.get();之后,系统会通过try-catch块无法捕获到Platform::COMException^异常。为什么?

有代码:

{
    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!");
        }
    });
}

有完整的异常消息:

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

然后Visual Studio将我扔到文件c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\exception中进行阻止:

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

已更新

环境:

  • Visual Studio 2017(15.7.3)
  • 基于cocos2d-x(3.16)的项目
  • Project Targe平台版本= 10.0.1493.0
  • 项目平台工具集= Visual Studio 2015(v140)

您可以克隆cocos2dx项目,并在之前在onEnter方法(或任何位置)中显示的MainScene粘贴代码中进行复制。

我遇到了当我100%撞车的情况

  1. 如果应用是以前构建的,则将其卸载;
  2. 断开与互联网的连接;
  3. 构建应用并启动;
  4. 该应用将尝试检测Channel URI并崩溃(但崩溃消息= WinRT information: The network is not present or not started)。

我知道抛出该异常是正常的。但是我仍然不明白为什么当我调用t.get()时没有捕获到异常Platform::COMException^

0 个答案:

没有答案
相关问题