capture exception information when creating exception_wrapper
authorEric Niebler <eniebler@fb.com>
Fri, 13 Jan 2017 20:16:51 +0000 (12:16 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 13 Jan 2017 20:18:00 +0000 (12:18 -0800)
Summary:
prefer creating an exception_wrapper with a reference to the active exception

Depends on D4410421

Reviewed By: spacedentist

Differential Revision: D4410455

fbshipit-source-id: d6b6aeb5fa72782e31d754a0b853514af5fdb8cd

folly/futures/detail/Core.h
folly/futures/test/PromiseTest.cpp
folly/futures/test/SharedPromiseTest.cpp

index 41fcdab2106376fe8939fd883741692377801f2e..be8e4b999be78941276993ab50666d0ce07de28c 100644 (file)
@@ -356,6 +356,7 @@ class Core final {
     }
 
     if (x) {
+      exception_wrapper ew;
       try {
         if (LIKELY(x->getNumPriorities() == 1)) {
           x->add([core_ref = CountedReference(this)]() mutable {
@@ -374,10 +375,15 @@ class Core final {
             core->callback_(std::move(*core->result_));
           }, priority);
         }
+      } catch (const std::exception& e) {
+        ew = exception_wrapper(std::current_exception(), e);
       } catch (...) {
+        ew = exception_wrapper(std::current_exception());
+      }
+      if (ew) {
         CountedReference core_ref(this);
         RequestContextScopeGuard rctx(context_);
-        result_ = Try<T>(exception_wrapper(std::current_exception()));
+        result_ = Try<T>(std::move(ew));
         SCOPE_EXIT { callback_ = {}; };
         callback_(std::move(*result_));
       }
index 559391a259ed9e21cdd6f651311343dd273d8ae6..ff9cef9cdc117016de938ecb37796272189e0461 100644 (file)
@@ -92,6 +92,8 @@ TEST(Promise, setException) {
     auto f = p.getFuture();
     try {
       throw eggs;
+    } catch (const std::exception& e) {
+      p.setException(exception_wrapper(std::current_exception(), e));
     } catch (...) {
       p.setException(exception_wrapper(std::current_exception()));
     }
index 7a4ea320be8c9217a446a5c89ea472c44f9de159..a449bf60026a0854abbc146b242da525962e7e9c 100644 (file)
@@ -146,8 +146,8 @@ TEST(SharedPromise, splitFutureFailure) {
   EXPECT_FALSE(f1.isReady());
   try {
     throw std::runtime_error("Oops");
-  } catch (...) {
-    p.setException(exception_wrapper(std::current_exception()));
+  } catch (const std::exception& e) {
+    p.setException(exception_wrapper(std::current_exception(), e));
   }
   EXPECT_TRUE(f1.isReady());
   EXPECT_TRUE(f1.hasException());