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.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of exceptions

exceptions

Photo of Coroutines

Coroutines

Related news:

News photo

Work-life balance wins as Australia embraces "right to disconnect" legislation | Some exceptions are made for emergencies and when communication is legally required

News photo

Duff's Device and Coroutines (2008)

News photo

My philosophy of exceptions: they're always ambiguous (2021)