From: James Sedgwick Date: Wed, 28 Jan 2015 19:01:44 +0000 (-0800) Subject: kill a couple unnecessary rethrows X-Git-Tag: v0.23.0~15 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;ds=sidebyside;h=32fc2d57869330179121f84b3a74aa44227cc5f5;p=folly.git kill a couple unnecessary rethrows Summary: as above, there were less of these than I expected, nice Test Plan: unit Reviewed By: hans@fb.com Subscribers: trunkagent, folly-diffs@, jsedgwick FB internal diff: D1789332 Tasks: 5949939 Signature: t1:1789332:1421878033:d7c2979a77b51a5257b8bcd910ad9296ca1aa7e0 --- diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index dd0f196d..e7d6954e 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -535,13 +535,10 @@ namespace { folly::detail::getTimekeeperSingleton()->after(dur) .then([&,token](Try const& t) { if (token->exchange(true) == false) { - try { - t.value(); + if (t.hasException()) { + p.setException(std::move(t.exception())); + } else { p.setException(TimedOut()); - } catch (std::exception const& e) { - p.setException(exception_wrapper(std::current_exception(), e)); - } catch (...) { - p.setException(exception_wrapper(std::current_exception())); } baton.post(); } @@ -627,15 +624,10 @@ Future Future::within(Duration dur, E e, Timekeeper* tk) { tk->after(dur) .then([ctx](Try const& t) { if (ctx->token.exchange(true) == false) { - try { - t.throwIfFailed(); + if (t.hasException()) { + ctx->promise.setException(std::move(t.exception())); + } else { ctx->promise.setException(std::move(ctx->exception)); - } catch (std::exception const& e2) { - ctx->promise.setException( - exception_wrapper(std::current_exception(), e2)); - } catch (...) { - ctx->promise.setException( - exception_wrapper(std::current_exception())); } } }); diff --git a/folly/futures/Try.h b/folly/futures/Try.h index 00008046..932a07e1 100644 --- a/folly/futures/Try.h +++ b/folly/futures/Try.h @@ -183,6 +183,13 @@ class Try { return *e_; } + const exception_wrapper& exception() const { + if (UNLIKELY(!hasException())) { + throw FutureException("exception(): Try does not contain an exception"); + } + return *e_; + } + /* * If the Try contains an exception and it is of type Ex, execute func(Ex) * @@ -295,6 +302,13 @@ class Try { return *e_; } + const exception_wrapper& exception() const { + if (UNLIKELY(!hasException())) { + throw FutureException("exception(): Try does not contain an exception"); + } + return *e_; + } + /* * If the Try contains an exception and it is of type Ex, execute func(Ex) *