Get the latest tech news
Throwing Exceptions from Coroutines
I want to throw exceptions from coroutines and I’m not taking no for an answer.
So, someone finaly figured out that it is stupid to require the overly complicated code for something as trivial as propagating the exception, made a defect report, and it was even reflected in the standard … in 2022, but at least it was retroactive, which means that it applies to C++20 even though it came out later. Doing this in pre-17 clang will leave the coroutine in a crazy state where its local variables want to be destroyed by both the exit of scope from throw and by handle.destroy(). On MSVC this fails when throwing an eager (pre first suspend) exception because of a double free of the coroutine state buffer.
Or read this on Hacker News