kill a couple unnecessary rethrows
authorJames Sedgwick <jsedgwick@fb.com>
Wed, 28 Jan 2015 19:01:44 +0000 (11:01 -0800)
committerwoo <woo@fb.com>
Mon, 2 Feb 2015 21:13:09 +0000 (13:13 -0800)
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

folly/futures/Future-inl.h
folly/futures/Try.h

index dd0f196d31cd56eea95f738202d25ed6e4eb6b77..e7d6954e5ff17223e90fcdaa50a8c5eb93f61fca 100644 (file)
@@ -535,13 +535,10 @@ namespace {
     folly::detail::getTimekeeperSingleton()->after(dur)
       .then([&,token](Try<void> 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<T> Future<T>::within(Duration dur, E e, Timekeeper* tk) {
   tk->after(dur)
     .then([ctx](Try<void> 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()));
         }
       }
     });
index 00008046699a5a72c4853a47ebb4545d4cf6cb54..932a07e1348c2f5cf1701e6c341c82133ea5c638 100644 (file)
@@ -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<void> {
     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)
    *