Is it valid to rethrow an unhandled C++ coroutine exception with `throw;`?
11:51 19 Dec 2025

Is the following code valid in a C++ coroutine promise object?

void
promise_type::unhandled_exception() noexcept
{
  try {
    // re-throw current exception
    throw;
  } catch (const std::exception &e) {
    std::println(stderr, "unhandled exception in coroutine: {}",
                 e.what());
    std::terminate();
  } catch (...) {
    std::println(stderr, "non-std::exception thrown");
    std::terminate();
  }
}

The alternative to throw; would be std::rethrow_exception(std::current_exception());. However, I find throw; much more readable, and it seems to work with both gcc and clang.

c++ exception c++20 coroutine