C++Winrt How to throw an exception from an async method

312 Views Asked by At

I have following code

IAsyncOperation<bool> trythiswork()
    {
        bool contentFound{ false };
        try
        {
            auto result = co_await someAsyncFunc();
            if (result)
            {
                throw;
                contentFound = true;
            }
        }
        catch (...)
        {
            LOG_CAUGHT_EXCEPTION();
        }
    }

But the catch block is never executed even when control goes to throw statement after the if condition is met. And control goes to contentFound = true; after the throw. Is there something wrong with how I am throwing from this method? Can you help me in throwing from this async method? I am expecting that catch block will be executed and the line contentFound = true; will not be executed. Thanks

0

There are 0 best solutions below