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 {
*/
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>&& t) noexcept;
......@@ -339,15 +332,8 @@ class Try<void> {
* @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<void>& t) {
......
......@@ -99,13 +99,7 @@ Promise<T>::setException(E const& e) {
template <class T>
void Promise<T>::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 <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