Commit 704df442 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

simplify catch clauses constructing exception_wrapper

Summary:
Now that `exception_wrapper` can access the exception object directly from the `std::exception_ptr`, it no longer needs to be passed the exception object separately.

This eliminates duplicative `catch (exception const&)` clauses which primarily construct `exception_wrapper` instances, reducing build artifact size.

Reviewed By: akrieger

Differential Revision: D27888763

fbshipit-source-id: 5f60a07083b3c8d818f0eafd5b17afcfca239ab8
parent fdc8edc2
...@@ -65,8 +65,8 @@ class File { ...@@ -65,8 +65,8 @@ class File {
static Expected<File, exception_wrapper> makeFile(Args&&... args) noexcept { static Expected<File, exception_wrapper> makeFile(Args&&... args) noexcept {
try { try {
return File(std::forward<Args>(args)...); return File(std::forward<Args>(args)...);
} catch (const std::system_error& se) { } catch (const std::system_error&) {
return makeUnexpected(exception_wrapper(std::current_exception(), se)); return makeUnexpected(exception_wrapper(std::current_exception()));
} }
} }
......
...@@ -255,8 +255,6 @@ makeTryWithNoUnwrap(F&& f) { ...@@ -255,8 +255,6 @@ makeTryWithNoUnwrap(F&& f) {
using ResultType = invoke_result_t<F>; using ResultType = invoke_result_t<F>;
try { try {
return Try<ResultType>(f()); return Try<ResultType>(f());
} catch (std::exception& e) {
return Try<ResultType>(exception_wrapper(std::current_exception(), e));
} catch (...) { } catch (...) {
return Try<ResultType>(exception_wrapper(std::current_exception())); return Try<ResultType>(exception_wrapper(std::current_exception()));
} }
...@@ -269,8 +267,6 @@ typename std:: ...@@ -269,8 +267,6 @@ typename std::
try { try {
f(); f();
return Try<void>(); return Try<void>();
} catch (std::exception& e) {
return Try<void>(exception_wrapper(std::current_exception(), e));
} catch (...) { } catch (...) {
return Try<void>(exception_wrapper(std::current_exception())); return Try<void>(exception_wrapper(std::current_exception()));
} }
...@@ -290,8 +286,6 @@ typename std::enable_if<isTry<invoke_result_t<F>>::value, invoke_result_t<F>>:: ...@@ -290,8 +286,6 @@ typename std::enable_if<isTry<invoke_result_t<F>>::value, invoke_result_t<F>>::
using ResultType = invoke_result_t<F>; using ResultType = invoke_result_t<F>;
try { try {
return f(); return f();
} catch (std::exception& e) {
return ResultType(exception_wrapper(std::current_exception(), e));
} catch (...) { } catch (...) {
return ResultType(exception_wrapper(std::current_exception())); return ResultType(exception_wrapper(std::current_exception()));
} }
...@@ -301,9 +295,6 @@ template <typename T, typename... Args> ...@@ -301,9 +295,6 @@ template <typename T, typename... Args>
T* tryEmplace(Try<T>& t, Args&&... args) noexcept { T* tryEmplace(Try<T>& t, Args&&... args) noexcept {
try { try {
return std::addressof(t.emplace(static_cast<Args&&>(args)...)); return std::addressof(t.emplace(static_cast<Args&&>(args)...));
} catch (const std::exception& ex) {
t.emplaceException(std::current_exception(), ex);
return nullptr;
} catch (...) { } catch (...) {
t.emplaceException(std::current_exception()); t.emplaceException(std::current_exception());
return nullptr; return nullptr;
...@@ -321,9 +312,6 @@ T* tryEmplaceWith(Try<T>& t, Func&& func) noexcept { ...@@ -321,9 +312,6 @@ T* tryEmplaceWith(Try<T>& t, Func&& func) noexcept {
"Unable to initialise a value of type T with the result of 'func'"); "Unable to initialise a value of type T with the result of 'func'");
try { try {
return std::addressof(t.emplace(static_cast<Func&&>(func)())); return std::addressof(t.emplace(static_cast<Func&&>(func)()));
} catch (const std::exception& ex) {
t.emplaceException(std::current_exception(), ex);
return nullptr;
} catch (...) { } catch (...) {
t.emplaceException(std::current_exception()); t.emplaceException(std::current_exception());
return nullptr; return nullptr;
...@@ -339,9 +327,6 @@ bool tryEmplaceWith(Try<void>& t, Func&& func) noexcept { ...@@ -339,9 +327,6 @@ bool tryEmplaceWith(Try<void>& t, Func&& func) noexcept {
static_cast<Func&&>(func)(); static_cast<Func&&>(func)();
t.emplace(); t.emplace();
return true; return true;
} catch (const std::exception& ex) {
t.emplaceException(std::current_exception(), ex);
return false;
} catch (...) { } catch (...) {
t.emplaceException(std::current_exception()); t.emplaceException(std::current_exception());
return false; return false;
...@@ -379,8 +364,6 @@ template <typename T> ...@@ -379,8 +364,6 @@ template <typename T>
void tryAssign(Try<T>& t, Try<T>&& other) noexcept { void tryAssign(Try<T>& t, Try<T>&& other) noexcept {
try { try {
t = std::move(other); t = std::move(other);
} catch (const std::exception& ex) {
t.emplaceException(std::current_exception(), ex);
} catch (...) { } catch (...) {
t.emplaceException(std::current_exception()); t.emplaceException(std::current_exception());
} }
......
...@@ -832,8 +832,6 @@ exception_wrapper SchemaValidator::try_validate( ...@@ -832,8 +832,6 @@ exception_wrapper SchemaValidator::try_validate(
if (auto se = validate(vc, value)) { if (auto se = validate(vc, value)) {
return make_exception_wrapper<SchemaError>(*se); return make_exception_wrapper<SchemaError>(*se);
} }
} catch (const std::exception& e) {
return exception_wrapper(std::current_exception(), e);
} catch (...) { } catch (...) {
return exception_wrapper(std::current_exception()); return exception_wrapper(std::current_exception());
} }
......
...@@ -207,8 +207,7 @@ class AsyncGeneratorPromise { ...@@ -207,8 +207,7 @@ class AsyncGeneratorPromise {
if (state_ == State::EXCEPTION_WRAPPER) { if (state_ == State::EXCEPTION_WRAPPER) {
return std::move(exceptionWrapper_.get()); return std::move(exceptionWrapper_.get());
} else { } else {
return exception_wrapper::from_exception_ptr( return exception_wrapper(std::move(exceptionPtr_.get()));
std::move(exceptionPtr_.get()));
} }
} }
......
...@@ -98,7 +98,7 @@ class BlockingWaitPromise final : public BlockingWaitPromiseBase { ...@@ -98,7 +98,7 @@ class BlockingWaitPromise final : public BlockingWaitPromiseBase {
void unhandled_exception() noexcept { void unhandled_exception() noexcept {
result_->emplaceException( result_->emplaceException(
folly::exception_wrapper::from_exception_ptr(std::current_exception())); folly::exception_wrapper{std::current_exception()});
} }
template < template <
...@@ -126,7 +126,7 @@ class BlockingWaitPromise<T&> final : public BlockingWaitPromiseBase { ...@@ -126,7 +126,7 @@ class BlockingWaitPromise<T&> final : public BlockingWaitPromiseBase {
void unhandled_exception() noexcept { void unhandled_exception() noexcept {
result_->emplaceException( result_->emplaceException(
folly::exception_wrapper::from_exception_ptr(std::current_exception())); folly::exception_wrapper{std::current_exception()});
} }
auto yield_value(T&& value) noexcept { auto yield_value(T&& value) noexcept {
...@@ -171,8 +171,7 @@ class BlockingWaitPromise<void> final : public BlockingWaitPromiseBase { ...@@ -171,8 +171,7 @@ class BlockingWaitPromise<void> final : public BlockingWaitPromiseBase {
void return_void() noexcept {} void return_void() noexcept {}
void unhandled_exception() noexcept { void unhandled_exception() noexcept {
result_->emplaceException( result_->emplaceException(exception_wrapper{std::current_exception()});
exception_wrapper::from_exception_ptr(std::current_exception()));
} }
void setTry(folly::Try<void>* result) noexcept { result_ = result; } void setTry(folly::Try<void>* result) noexcept { result_ = result; }
......
...@@ -59,11 +59,6 @@ BarrierTask makeCollectAllTryTask( ...@@ -59,11 +59,6 @@ BarrierTask makeCollectAllTryTask(
co_withCancellation( co_withCancellation(
cancelToken, static_cast<SemiAwaitable&&>(awaitable)))); cancelToken, static_cast<SemiAwaitable&&>(awaitable))));
} }
// This causes clang internal error on Windows.
#if !(defined(_WIN32) && defined(__clang__))
} catch (const std::exception& ex) {
result.emplaceException(std::current_exception(), ex);
#endif
} catch (...) { } catch (...) {
result.emplaceException(std::current_exception()); result.emplaceException(std::current_exception());
} }
...@@ -156,12 +151,6 @@ auto collectAllImpl( ...@@ -156,12 +151,6 @@ auto collectAllImpl(
co_withCancellation( co_withCancellation(
cancelToken, static_cast<decltype(awaitable)>(awaitable)))); cancelToken, static_cast<decltype(awaitable)>(awaitable))));
} }
} catch (const std::exception& ex) {
anyFailures.store(true, std::memory_order_relaxed);
if (!cancelSource.requestCancellation()) {
// This was the first failure, remember it's error.
firstException = exception_wrapper{std::current_exception(), ex};
}
} catch (...) { } catch (...) {
anyFailures.store(true, std::memory_order_relaxed); anyFailures.store(true, std::memory_order_relaxed);
if (!cancelSource.requestCancellation()) { if (!cancelSource.requestCancellation()) {
...@@ -339,11 +328,6 @@ auto collectAllRange(InputRange awaitables) ...@@ -339,11 +328,6 @@ auto collectAllRange(InputRange awaitables)
tryResults[index].emplace(co_await co_viaIfAsync( tryResults[index].emplace(co_await co_viaIfAsync(
executor.get_alias(), executor.get_alias(),
co_withCancellation(cancelToken, std::move(semiAwaitable)))); co_withCancellation(cancelToken, std::move(semiAwaitable))));
} catch (const std::exception& ex) {
anyFailures.store(true, std::memory_order_relaxed);
if (!cancelSource.requestCancellation()) {
firstException = exception_wrapper{std::current_exception(), ex};
}
} catch (...) { } catch (...) {
anyFailures.store(true, std::memory_order_relaxed); anyFailures.store(true, std::memory_order_relaxed);
if (!cancelSource.requestCancellation()) { if (!cancelSource.requestCancellation()) {
...@@ -430,11 +414,6 @@ auto collectAllRange(InputRange awaitables) -> folly::coro::Task<void> { ...@@ -430,11 +414,6 @@ auto collectAllRange(InputRange awaitables) -> folly::coro::Task<void> {
co_await co_viaIfAsync( co_await co_viaIfAsync(
executor.get_alias(), executor.get_alias(),
co_withCancellation(cancelToken, std::move(semiAwaitable))); co_withCancellation(cancelToken, std::move(semiAwaitable)));
} catch (const std::exception& ex) {
anyFailures.store(true, std::memory_order_relaxed);
if (!cancelSource.requestCancellation()) {
firstException = exception_wrapper{std::current_exception(), ex};
}
} catch (...) { } catch (...) {
anyFailures.store(true, std::memory_order_relaxed); anyFailures.store(true, std::memory_order_relaxed);
if (!cancelSource.requestCancellation()) { if (!cancelSource.requestCancellation()) {
...@@ -510,12 +489,6 @@ auto collectAllTryRange(InputRange awaitables) ...@@ -510,12 +489,6 @@ auto collectAllTryRange(InputRange awaitables)
executor.get_alias(), executor.get_alias(),
co_withCancellation(cancelToken, std::move(semiAwaitable)))); co_withCancellation(cancelToken, std::move(semiAwaitable))));
} }
// This causes "Instruction does not dominate all uses!" internal compiler
// error on Windows with Clang.
#if !(defined(_WIN32) && defined(__clang__))
} catch (const std::exception& ex) {
result.emplaceException(std::current_exception(), ex);
#endif
} catch (...) { } catch (...) {
result.emplaceException(std::current_exception()); result.emplaceException(std::current_exception());
} }
...@@ -608,9 +581,6 @@ auto collectAllWindowed(InputRange awaitables, std::size_t maxConcurrency) ...@@ -608,9 +581,6 @@ auto collectAllWindowed(InputRange awaitables, std::size_t maxConcurrency)
try { try {
awaitable.emplace(*iter); awaitable.emplace(*iter);
++iter; ++iter;
} catch (const std::exception& ex) {
iterationException = exception_wrapper{std::current_exception(), ex};
cancelSource.requestCancellation();
} catch (...) { } catch (...) {
iterationException = exception_wrapper{std::current_exception()}; iterationException = exception_wrapper{std::current_exception()};
cancelSource.requestCancellation(); cancelSource.requestCancellation();
...@@ -626,8 +596,6 @@ auto collectAllWindowed(InputRange awaitables, std::size_t maxConcurrency) ...@@ -626,8 +596,6 @@ auto collectAllWindowed(InputRange awaitables, std::size_t maxConcurrency)
co_await co_viaIfAsync( co_await co_viaIfAsync(
executor.get_alias(), executor.get_alias(),
co_withCancellation(cancelToken, std::move(*awaitable))); co_withCancellation(cancelToken, std::move(*awaitable)));
} catch (const std::exception& ex) {
trySetFirstException(exception_wrapper{std::current_exception(), ex});
} catch (...) { } catch (...) {
trySetFirstException(exception_wrapper{std::current_exception()}); trySetFirstException(exception_wrapper{std::current_exception()});
} }
...@@ -669,11 +637,6 @@ auto collectAllWindowed(InputRange awaitables, std::size_t maxConcurrency) ...@@ -669,11 +637,6 @@ auto collectAllWindowed(InputRange awaitables, std::size_t maxConcurrency)
lock = co_await mutex.co_scoped_lock(); lock = co_await mutex.co_scoped_lock();
} }
} catch (const std::exception& ex) {
// Only a fatal error if we failed to create any worker tasks.
if (workerTasks.empty()) {
iterationException = exception_wrapper{std::current_exception(), ex};
}
} catch (...) { } catch (...) {
if (workerTasks.empty()) { if (workerTasks.empty()) {
iterationException = exception_wrapper{std::current_exception()}; iterationException = exception_wrapper{std::current_exception()};
...@@ -748,9 +711,6 @@ auto collectAllWindowed(InputRange awaitables, std::size_t maxConcurrency) ...@@ -748,9 +711,6 @@ auto collectAllWindowed(InputRange awaitables, std::size_t maxConcurrency)
tryResults.emplace_back(); tryResults.emplace_back();
awaitable.emplace(*iter); awaitable.emplace(*iter);
++iter; ++iter;
} catch (const std::exception& ex) {
iterationException = exception_wrapper{std::current_exception(), ex};
cancelSource.requestCancellation();
} catch (...) { } catch (...) {
iterationException = exception_wrapper{std::current_exception()}; iterationException = exception_wrapper{std::current_exception()};
cancelSource.requestCancellation(); cancelSource.requestCancellation();
...@@ -771,8 +731,6 @@ auto collectAllWindowed(InputRange awaitables, std::size_t maxConcurrency) ...@@ -771,8 +731,6 @@ auto collectAllWindowed(InputRange awaitables, std::size_t maxConcurrency)
executor.get_alias(), executor.get_alias(),
co_withCancellation( co_withCancellation(
cancelToken, static_cast<awaitable_t&&>(*awaitable)))); cancelToken, static_cast<awaitable_t&&>(*awaitable))));
} catch (const std::exception& ex) {
trySetFirstException(exception_wrapper{std::current_exception(), ex});
} catch (...) { } catch (...) {
trySetFirstException(exception_wrapper{std::current_exception()}); trySetFirstException(exception_wrapper{std::current_exception()});
} }
...@@ -782,8 +740,6 @@ auto collectAllWindowed(InputRange awaitables, std::size_t maxConcurrency) ...@@ -782,8 +740,6 @@ auto collectAllWindowed(InputRange awaitables, std::size_t maxConcurrency)
try { try {
tryResults[thisIndex] = std::move(tryResult); tryResults[thisIndex] = std::move(tryResult);
} catch (const std::exception& ex) {
trySetFirstException(exception_wrapper{std::current_exception(), ex});
} catch (...) { } catch (...) {
trySetFirstException(exception_wrapper{std::current_exception()}); trySetFirstException(exception_wrapper{std::current_exception()});
} }
...@@ -824,14 +780,10 @@ auto collectAllWindowed(InputRange awaitables, std::size_t maxConcurrency) ...@@ -824,14 +780,10 @@ auto collectAllWindowed(InputRange awaitables, std::size_t maxConcurrency)
lock = co_await mutex.co_scoped_lock(); lock = co_await mutex.co_scoped_lock();
} }
} catch (const std::exception& ex) { } catch (...) {
// Only a fatal error if we failed to create any worker tasks. // Only a fatal error if we failed to create any worker tasks.
if (workerTasks.empty()) { if (workerTasks.empty()) {
// No need to synchronise here. There are no concurrent tasks running. // No need to synchronise here. There are no concurrent tasks running.
iterationException = exception_wrapper{std::current_exception(), ex};
}
} catch (...) {
if (workerTasks.empty()) {
iterationException = exception_wrapper{std::current_exception()}; iterationException = exception_wrapper{std::current_exception()};
} }
} }
...@@ -899,8 +851,6 @@ auto collectAllTryWindowed(InputRange awaitables, std::size_t maxConcurrency) ...@@ -899,8 +851,6 @@ auto collectAllTryWindowed(InputRange awaitables, std::size_t maxConcurrency)
results.emplace_back(); results.emplace_back();
awaitable.emplace(*iter); awaitable.emplace(*iter);
++iter; ++iter;
} catch (const std::exception& ex) {
iterationException = exception_wrapper{std::current_exception(), ex};
} catch (...) { } catch (...) {
iterationException = exception_wrapper{std::current_exception()}; iterationException = exception_wrapper{std::current_exception()};
} }
...@@ -926,8 +876,6 @@ auto collectAllTryWindowed(InputRange awaitables, std::size_t maxConcurrency) ...@@ -926,8 +876,6 @@ auto collectAllTryWindowed(InputRange awaitables, std::size_t maxConcurrency)
executor.get_alias(), executor.get_alias(),
co_withCancellation(cancelToken, std::move(*awaitable)))); co_withCancellation(cancelToken, std::move(*awaitable))));
} }
} catch (const std::exception& ex) {
result.emplaceException(std::current_exception(), ex);
} catch (...) { } catch (...) {
result.emplaceException(std::current_exception()); result.emplaceException(std::current_exception());
} }
...@@ -937,8 +885,6 @@ auto collectAllTryWindowed(InputRange awaitables, std::size_t maxConcurrency) ...@@ -937,8 +885,6 @@ auto collectAllTryWindowed(InputRange awaitables, std::size_t maxConcurrency)
try { try {
results[thisIndex] = std::move(result); results[thisIndex] = std::move(result);
} catch (const std::exception& ex) {
results[thisIndex].emplaceException(std::current_exception(), ex);
} catch (...) { } catch (...) {
results[thisIndex].emplaceException(std::current_exception()); results[thisIndex].emplaceException(std::current_exception());
} }
...@@ -976,14 +922,10 @@ auto collectAllTryWindowed(InputRange awaitables, std::size_t maxConcurrency) ...@@ -976,14 +922,10 @@ auto collectAllTryWindowed(InputRange awaitables, std::size_t maxConcurrency)
lock = co_await mutex.co_scoped_lock(); lock = co_await mutex.co_scoped_lock();
} }
} catch (const std::exception& ex) { } catch (...) {
// Failure to create a worker is an error if we failed // Failure to create a worker is an error if we failed
// to create _any_ workers. As long as we created one then // to create _any_ workers. As long as we created one then
// the algorithm should still be able to make forward progress. // the algorithm should still be able to make forward progress.
if (workerTasks.empty()) {
iterationException = exception_wrapper{std::current_exception(), ex};
}
} catch (...) {
if (workerTasks.empty()) { if (workerTasks.empty()) {
iterationException = exception_wrapper{std::current_exception()}; iterationException = exception_wrapper{std::current_exception()};
} }
......
...@@ -29,8 +29,6 @@ AsyncGenerator<CallbackRecord<Reference>, CallbackRecord<Value>> materialize( ...@@ -29,8 +29,6 @@ AsyncGenerator<CallbackRecord<Reference>, CallbackRecord<Value>> materialize(
while (auto item = co_await source.next()) { while (auto item = co_await source.next()) {
co_yield EventType{callback_record_value, *std::move(item)}; co_yield EventType{callback_record_value, *std::move(item)};
} }
} catch (const std::exception& e) {
ex = folly::exception_wrapper{std::current_exception(), e};
} catch (...) { } catch (...) {
ex = folly::exception_wrapper{std::current_exception()}; ex = folly::exception_wrapper{std::current_exception()};
} }
......
...@@ -94,8 +94,6 @@ AsyncGenerator<Reference, Value> merge( ...@@ -94,8 +94,6 @@ AsyncGenerator<Reference, Value> merge(
break; break;
} }
} }
} catch (const std::exception& e) {
ex = exception_wrapper{std::current_exception(), e};
} catch (...) { } catch (...) {
ex = exception_wrapper{std::current_exception()}; ex = exception_wrapper{std::current_exception()};
} }
...@@ -125,8 +123,6 @@ AsyncGenerator<Reference, Value> merge( ...@@ -125,8 +123,6 @@ AsyncGenerator<Reference, Value> merge(
} }
makeWorkerTask(state, *std::move(item)).start(&barrier, asyncFrame); makeWorkerTask(state, *std::move(item)).start(&barrier, asyncFrame);
} }
} catch (const std::exception& e) {
ex = exception_wrapper{std::current_exception(), e};
} catch (...) { } catch (...) {
ex = exception_wrapper{std::current_exception()}; ex = exception_wrapper{std::current_exception()};
} }
......
...@@ -66,8 +66,6 @@ auto retryWhen(Func func, RetryDelayFunc retryDelay) ...@@ -66,8 +66,6 @@ auto retryWhen(Func func, RetryDelayFunc retryDelay)
assert(result.hasException()); assert(result.hasException());
error = std::move(result.exception()); error = std::move(result.exception());
} }
} catch (const std::exception& e) {
error = exception_wrapper(std::current_exception(), e);
} catch (...) { } catch (...) {
error = exception_wrapper(std::current_exception()); error = exception_wrapper(std::current_exception());
} }
......
...@@ -154,8 +154,7 @@ class TaskPromise : public TaskPromiseBase { ...@@ -154,8 +154,7 @@ class TaskPromise : public TaskPromiseBase {
Task<T> get_return_object() noexcept; Task<T> get_return_object() noexcept;
void unhandled_exception() noexcept { void unhandled_exception() noexcept {
result_.emplaceException( result_.emplaceException(exception_wrapper{std::current_exception()});
exception_wrapper::from_exception_ptr(std::current_exception()));
} }
template <typename U = T> template <typename U = T>
...@@ -211,8 +210,7 @@ class TaskPromise<void> : public TaskPromiseBase { ...@@ -211,8 +210,7 @@ class TaskPromise<void> : public TaskPromiseBase {
Task<void> get_return_object() noexcept; Task<void> get_return_object() noexcept;
void unhandled_exception() noexcept { void unhandled_exception() noexcept {
result_.emplaceException( result_.emplaceException(exception_wrapper{std::current_exception()});
exception_wrapper::from_exception_ptr(std::current_exception()));
} }
void return_void() noexcept { result_.emplace(); } void return_void() noexcept { result_.emplace(); }
...@@ -360,11 +358,6 @@ class FOLLY_NODISCARD TaskWithExecutor { ...@@ -360,11 +358,6 @@ class FOLLY_NODISCARD TaskWithExecutor {
detail::InlineTaskDetached startImpl(TaskWithExecutor task, F cb) { detail::InlineTaskDetached startImpl(TaskWithExecutor task, F cb) {
try { try {
cb(co_await folly::coro::co_awaitTry(std::move(task))); cb(co_await folly::coro::co_awaitTry(std::move(task)));
// This causes clang internal error on Windows.
#if !(defined(_WIN32) && defined(__clang__))
} catch (const std::exception& e) {
cb(Try<StorageType>(exception_wrapper(std::current_exception(), e)));
#endif
} catch (...) { } catch (...) {
cb(Try<StorageType>(exception_wrapper(std::current_exception()))); cb(Try<StorageType>(exception_wrapper(std::current_exception())));
} }
...@@ -374,11 +367,6 @@ class FOLLY_NODISCARD TaskWithExecutor { ...@@ -374,11 +367,6 @@ class FOLLY_NODISCARD TaskWithExecutor {
detail::InlineTaskDetached startInlineImpl(TaskWithExecutor task, F cb) { detail::InlineTaskDetached startInlineImpl(TaskWithExecutor task, F cb) {
try { try {
cb(co_await InlineTryAwaitable{std::exchange(task.coro_, {})}); cb(co_await InlineTryAwaitable{std::exchange(task.coro_, {})});
// This causes clang internal error on Windows.
#if !(defined(_WIN32) && defined(__clang__))
} catch (const std::exception& e) {
cb(Try<StorageType>(exception_wrapper(std::current_exception(), e)));
#endif
} catch (...) { } catch (...) {
cb(Try<StorageType>(exception_wrapper(std::current_exception()))); cb(Try<StorageType>(exception_wrapper(std::current_exception())));
} }
......
...@@ -82,8 +82,6 @@ Task<typename semi_await_try_result_t<SemiAwaitable>::element_type> timeout( ...@@ -82,8 +82,6 @@ Task<typename semi_await_try_result_t<SemiAwaitable>::element_type> timeout(
} }
co_return std::move(resultTry).value(); co_return std::move(resultTry).value();
} catch (const std::exception& ex) {
error = exception_wrapper{std::current_exception(), ex};
} catch (...) { } catch (...) {
error = exception_wrapper{std::current_exception()}; error = exception_wrapper{std::current_exception()};
} }
......
...@@ -116,7 +116,7 @@ class InlineTaskPromise : public InlineTaskPromiseBase { ...@@ -116,7 +116,7 @@ class InlineTaskPromise : public InlineTaskPromiseBase {
void unhandled_exception() noexcept { void unhandled_exception() noexcept {
result_.emplaceException( result_.emplaceException(
folly::exception_wrapper::from_exception_ptr(std::current_exception())); folly::exception_wrapper{std::current_exception()});
} }
T result() { return std::move(result_).value(); } T result() { return std::move(result_).value(); }
...@@ -143,7 +143,7 @@ class InlineTaskPromise<void> : public InlineTaskPromiseBase { ...@@ -143,7 +143,7 @@ class InlineTaskPromise<void> : public InlineTaskPromiseBase {
void unhandled_exception() noexcept { void unhandled_exception() noexcept {
result_.emplaceException( result_.emplaceException(
folly::exception_wrapper::from_exception_ptr(std::current_exception())); folly::exception_wrapper{std::current_exception()});
} }
void result() { return result_.value(); } void result() { return result_.value(); }
......
...@@ -122,11 +122,6 @@ class BatchDispatcher { ...@@ -122,11 +122,6 @@ class BatchDispatcher {
for (size_t i = 0; i < promises.size(); i++) { for (size_t i = 0; i < promises.size(); i++) {
promises[i].setValue(std::move(results[i])); promises[i].setValue(std::move(results[i]));
} }
} catch (const std::exception& ex) {
for (size_t i = 0; i < promises.size(); i++) {
promises[i].setException(
exception_wrapper(std::current_exception(), ex));
}
} catch (...) { } catch (...) {
for (size_t i = 0; i < promises.size(); i++) { for (size_t i = 0; i < promises.size(); i++) {
promises[i].setException(exception_wrapper(std::current_exception())); promises[i].setException(exception_wrapper(std::current_exception()));
......
...@@ -587,9 +587,6 @@ makeSemiFutureWith(F&& func) { ...@@ -587,9 +587,6 @@ makeSemiFutureWith(F&& func) {
using InnerType = typename isFutureOrSemiFuture<invoke_result_t<F>>::Inner; using InnerType = typename isFutureOrSemiFuture<invoke_result_t<F>>::Inner;
try { try {
return static_cast<F&&>(func)(); return static_cast<F&&>(func)();
} catch (std::exception& e) {
return makeSemiFuture<InnerType>(
exception_wrapper(std::current_exception(), e));
} catch (...) { } catch (...) {
return makeSemiFuture<InnerType>( return makeSemiFuture<InnerType>(
exception_wrapper(std::current_exception())); exception_wrapper(std::current_exception()));
...@@ -1239,9 +1236,6 @@ typename std:: ...@@ -1239,9 +1236,6 @@ typename std::
using InnerType = typename isFuture<invoke_result_t<F>>::Inner; using InnerType = typename isFuture<invoke_result_t<F>>::Inner;
try { try {
return static_cast<F&&>(func)(); return static_cast<F&&>(func)();
} catch (std::exception& e) {
return makeFuture<InnerType>(
exception_wrapper(std::current_exception(), e));
} catch (...) { } catch (...) {
return makeFuture<InnerType>(exception_wrapper(std::current_exception())); return makeFuture<InnerType>(exception_wrapper(std::current_exception()));
} }
...@@ -1915,8 +1909,6 @@ SemiFuture<T> unorderedReduceSemiFuture(It first, It last, T initial, F func) { ...@@ -1915,8 +1909,6 @@ SemiFuture<T> unorderedReduceSemiFuture(It first, It last, T initial, F func) {
ctx->func_( ctx->func_(
std::move(v.value()), std::move(v.value()),
mt.template get<IsTry::value, Arg&&>())); mt.template get<IsTry::value, Arg&&>()));
} catch (std::exception& e) {
ew = exception_wrapper{std::current_exception(), e};
} catch (...) { } catch (...) {
ew = exception_wrapper{std::current_exception()}; ew = exception_wrapper{std::current_exception()};
} }
......
...@@ -239,7 +239,7 @@ class Promise { ...@@ -239,7 +239,7 @@ class Promise {
/// Promise<MyValue> p = ... /// Promise<MyValue> p = ...
/// ... /// ...
/// auto const ep = std::exception_ptr(); /// auto const ep = std::exception_ptr();
/// auto const ew = exception_wrapper::from_exception_ptr(ep); /// auto const ew = exception_wrapper{ep};
/// p.setException(ew); /// p.setException(ew);
/// ///
/// Functionally equivalent to `setTry(Try<T>(std::move(ew)))` /// Functionally equivalent to `setTry(Try<T>(std::move(ew)))`
......
...@@ -532,8 +532,6 @@ void CoreBase::doCallback( ...@@ -532,8 +532,6 @@ void CoreBase::doCallback(
RequestContextScopeGuard rctx(std::move(core->context_)); RequestContextScopeGuard rctx(std::move(core->context_));
core->callback_(*core, std::move(ka), nullptr); core->callback_(*core, std::move(ka), nullptr);
}); });
} catch (const std::exception& e) {
ew = exception_wrapper(std::current_exception(), e);
} catch (...) { } catch (...) {
ew = exception_wrapper(std::current_exception()); ew = exception_wrapper(std::current_exception());
} }
......
...@@ -165,11 +165,7 @@ TEST(FutureSplitter, splitFutureFailure) { ...@@ -165,11 +165,7 @@ TEST(FutureSplitter, splitFutureFailure) {
p.getSemiFuture().via(&InlineExecutor::instance())); p.getSemiFuture().via(&InlineExecutor::instance()));
auto f1 = sp.getFuture(); auto f1 = sp.getFuture();
EXPECT_FALSE(f1.isReady()); EXPECT_FALSE(f1.isReady());
try { p.setException(exception_wrapper{std::runtime_error("Oops")});
throw std::runtime_error("Oops");
} catch (std::exception& e) {
p.setException(exception_wrapper(std::current_exception(), e));
}
EXPECT_TRUE(f1.isReady()); EXPECT_TRUE(f1.isReady());
EXPECT_TRUE(f1.hasException()); EXPECT_TRUE(f1.hasException());
auto f2 = sp.getFuture(); auto f2 = sp.getFuture();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment