Print why we called std::terminate
authorPhil Willoughby <philwill@fb.com>
Wed, 12 Oct 2016 09:44:45 +0000 (02:44 -0700)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Wed, 12 Oct 2016 09:53:30 +0000 (02:53 -0700)
Summary:
When terminating because we were told to rethrow a nonexistent exception, we
now print that to `std::cerr` for the benefit of users on platforms which do not dump a stack trace on
`std::terminate`

Reviewed By: yfeldblum

Differential Revision: D4001087

fbshipit-source-id: 5b834cfc75bf42bec06a49ac9db55789a83df180

folly/ExceptionWrapper.h
folly/test/ExceptionWrapperTest.cpp

index 94f6e82825fb927ba8eb9ffb70eb7035c80009d3..df40f040367efb85e37dcd56cae294c45d564a85 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <cassert>
 #include <exception>
+#include <iostream>
 #include <memory>
 #include <folly/ExceptionString.h>
 #include <folly/detail/ExceptionWrapper.h>
@@ -156,6 +157,9 @@ class exception_wrapper {
     } else if (eptr_) {
       std::rethrow_exception(eptr_);
     }
+    std::cerr
+        << "Cannot use `throwException` with an empty folly::exception_wrapper"
+        << std::endl;
     std::terminate();
   }
 
index e42f9941bd42c8b9c99cbdea2f00e0679840404c..e5e40d0553190cbdb760fc17ebeac085a4f96b55 100644 (file)
@@ -306,7 +306,7 @@ TEST(ExceptionWrapper, exceptionStr) {
 
 TEST(ExceptionWrapper, throwException_noException) {
   exception_wrapper ew;
-  ASSERT_DEATH(ew.throwException(), "exception");
+  ASSERT_DEATH(ew.throwException(), "empty folly::exception_wrapper");
 }
 
 namespace {