Is it valid to rethrow an unhandled C++ coroutine exception with `throw;`?

16 hours ago 2
ARTICLE AD BOX

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.

Read Entire Article