From: Phil Willoughby Date: Wed, 12 Oct 2016 09:44:45 +0000 (-0700) Subject: Print why we called std::terminate X-Git-Tag: v2016.10.17.00~12 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=fec7b1bc321fa6faa4af5a57d7b29ecc363ff7dc;p=folly.git Print why we called std::terminate 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 --- diff --git a/folly/ExceptionWrapper.h b/folly/ExceptionWrapper.h index 94f6e828..df40f040 100644 --- a/folly/ExceptionWrapper.h +++ b/folly/ExceptionWrapper.h @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -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(); } diff --git a/folly/test/ExceptionWrapperTest.cpp b/folly/test/ExceptionWrapperTest.cpp index e42f9941..e5e40d05 100644 --- a/folly/test/ExceptionWrapperTest.cpp +++ b/folly/test/ExceptionWrapperTest.cpp @@ -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 {