From 1eccb2e616d848a21699bd11b04622d0ef7b07c3 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Mon, 21 Aug 2017 21:10:34 -0700 Subject: [PATCH] Use exception_wrapper::from_exception_ptr in Try and Promise Summary: [Folly] Use `exception_wrapper::from_exception_ptr` in `Try` and `Promise`. It does just what we need; DRY. Reviewed By: andrewjcg Differential Revision: D5674663 fbshipit-source-id: 73e46df62c06736c4eaf013d05dfea819cbec515 --- folly/Try.h | 22 ++++------------------ folly/futures/Promise-inl.h | 8 +------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/folly/Try.h b/folly/Try.h index f38362b8..fb783b01 100644 --- a/folly/Try.h +++ b/folly/Try.h @@ -114,15 +114,8 @@ class Try { */ FOLLY_DEPRECATED("use Try(exception_wrapper)") explicit Try(std::exception_ptr ep) - : contains_(Contains::EXCEPTION) { - try { - std::rethrow_exception(ep); - } catch (std::exception& e) { - e_ = exception_wrapper(std::current_exception(), e); - } catch (...) { - e_ = exception_wrapper(std::current_exception()); - } - } + : contains_(Contains::EXCEPTION), + e_(exception_wrapper::from_exception_ptr(ep)) {} // Move constructor Try(Try&& t) noexcept; @@ -339,15 +332,8 @@ class Try { * @param ep The exception_pointer. Will be rethrown. */ FOLLY_DEPRECATED("use Try(exception_wrapper)") - explicit Try(std::exception_ptr ep) : hasValue_(false) { - try { - std::rethrow_exception(ep); - } catch (const std::exception& e) { - e_ = exception_wrapper(std::current_exception(), e); - } catch (...) { - e_ = exception_wrapper(std::current_exception()); - } - } + explicit Try(std::exception_ptr ep) + : hasValue_(false), e_(exception_wrapper::from_exception_ptr(ep)) {} // Copy assigner Try& operator=(const Try& t) { diff --git a/folly/futures/Promise-inl.h b/folly/futures/Promise-inl.h index 3c6ff173..5fe4ed2c 100644 --- a/folly/futures/Promise-inl.h +++ b/folly/futures/Promise-inl.h @@ -99,13 +99,7 @@ Promise::setException(E const& e) { template void Promise::setException(std::exception_ptr const& ep) { - try { - std::rethrow_exception(ep); - } catch (const std::exception& e) { - setException(exception_wrapper(std::current_exception(), e)); - } catch (...) { - setException(exception_wrapper(std::current_exception())); - } + setException(exception_wrapper::from_exception_ptr(ep)); } template -- 2.34.1