Hi @金旺 王 ,
Welcome to Microsoft Q&A!
I use your code and test it in UWP C++/WinRT project, and the wait() cannot be used in UWP.
If you want to get Exception in concurrency::task<void> t
, you need to re-throw the Exception in Concurrency::task<void> previousTask
to pass the exception to task t.
Concurrency::create_task(_listener->BindServiceNameAsync("555")).then(
[this](Concurrency::task<void> previousTask)
{
try
{
// Try getting an exception.
// previousTask.get();
throw ref new Platform::Exception(E_FAIL);
}
catch (...)
{
OutputDebugString(L"Platform::Exception");
throw;
}
return previousTask;
}).then([](concurrency::task< void > t)
{
try
{
t.get();
// .get() didn't throw, so we succeeded.
}
catch (...)
{
OutputDebugString(L"Platform::Exception 2");
}
}).wait();
Thank you.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.