@@ -161,25 +161,36 @@ class AsyncScope {
161161 std::is_same_v<await_result_t <Awaitable>, folly::Unit>,
162162 " Result of the task would be discarded. Make sure task result is either void or folly::Unit." );
163163
164+ exception_wrapper exn;
164165 try {
165- co_await std::move (awaitable);
166- } catch (const OperationCancelled&) {
166+ if constexpr (detail::is_awaitable_try<Awaitable>) {
167+ auto ret = co_await co_awaitTry (std::move (awaitable));
168+ if (ret.hasException ()) {
169+ exn = std::move (ret.exception ());
170+ }
171+ } else {
172+ co_await std::move (awaitable);
173+ }
167174 } catch (...) {
175+ // not-awaitable-try awaitables and not-noexcept-copy-constructible values
176+ exn = exception_wrapper (std::current_exception ());
177+ }
178+ if (exn && !exn.get_exception <OperationCancelled>()) {
168179 if (throwOnJoin) {
169180 LOG (ERROR)
170181 << (source.has_value () ? sourceLocationToString (source.value ())
171182 : " " )
172183 << " Unhandled exception thrown from task added to AsyncScope: "
173- << folly::exceptionStr ( current_exception ()) ;
184+ << exn ;
174185 if (!exceptionRaised.exchange (true )) {
175- maybeException = folly::exception_wrapper ( current_exception () );
186+ maybeException = std::move (exn );
176187 }
177188 } else {
178189 LOG (DFATAL)
179190 << (source.has_value () ? sourceLocationToString (source.value ())
180191 : " " )
181192 << " Unhandled exception thrown from task added to AsyncScope: "
182- << folly::exceptionStr ( current_exception ()) ;
193+ << exn ;
183194 }
184195 }
185196 }
@@ -255,8 +266,8 @@ inline Task<void> AsyncScope::joinAsync() noexcept {
255266 joinStarted_.store (true , std::memory_order_relaxed);
256267 co_await barrier_.arriveAndWait ();
257268 joined_ = true ;
258- if (maybeException_. has_exception_ptr () ) {
259- maybeException_. throw_exception () ;
269+ if (maybeException_) {
270+ co_yield co_error{ std::move (maybeException_)} ;
260271 }
261272}
262273
0 commit comments