Commit 1eccb2e6 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

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
parent 2ca5653c
...@@ -114,15 +114,8 @@ class Try { ...@@ -114,15 +114,8 @@ class Try {
*/ */
FOLLY_DEPRECATED("use Try(exception_wrapper)") FOLLY_DEPRECATED("use Try(exception_wrapper)")
explicit Try(std::exception_ptr ep) explicit Try(std::exception_ptr ep)
: contains_(Contains::EXCEPTION) { : contains_(Contains::EXCEPTION),
try { e_(exception_wrapper::from_exception_ptr(ep)) {}
std::rethrow_exception(ep);
} catch (std::exception& e) {
e_ = exception_wrapper(std::current_exception(), e);
} catch (...) {
e_ = exception_wrapper(std::current_exception());
}
}
// Move constructor // Move constructor
Try(Try<T>&& t) noexcept; Try(Try<T>&& t) noexcept;
...@@ -339,15 +332,8 @@ class Try<void> { ...@@ -339,15 +332,8 @@ class Try<void> {
* @param ep The exception_pointer. Will be rethrown. * @param ep The exception_pointer. Will be rethrown.
*/ */
FOLLY_DEPRECATED("use Try(exception_wrapper)") FOLLY_DEPRECATED("use Try(exception_wrapper)")
explicit Try(std::exception_ptr ep) : hasValue_(false) { explicit Try(std::exception_ptr ep)
try { : hasValue_(false), e_(exception_wrapper::from_exception_ptr(ep)) {}
std::rethrow_exception(ep);
} catch (const std::exception& e) {
e_ = exception_wrapper(std::current_exception(), e);
} catch (...) {
e_ = exception_wrapper(std::current_exception());
}
}
// Copy assigner // Copy assigner
Try& operator=(const Try<void>& t) { Try& operator=(const Try<void>& t) {
......
...@@ -99,13 +99,7 @@ Promise<T>::setException(E const& e) { ...@@ -99,13 +99,7 @@ Promise<T>::setException(E const& e) {
template <class T> template <class T>
void Promise<T>::setException(std::exception_ptr const& ep) { void Promise<T>::setException(std::exception_ptr const& ep) {
try { setException(exception_wrapper::from_exception_ptr(ep));
std::rethrow_exception(ep);
} catch (const std::exception& e) {
setException(exception_wrapper(std::current_exception(), e));
} catch (...) {
setException(exception_wrapper(std::current_exception()));
}
} }
template <class T> template <class T>
......
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