Let exception_wrapper::handle, when empty, show the right error message v2017.07.17.00
authorYedidya Feldblum <yfeldblum@fb.com>
Mon, 17 Jul 2017 05:07:08 +0000 (22:07 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Mon, 17 Jul 2017 05:19:45 +0000 (22:19 -0700)
Summary:
[Folly] Let `exception_wrapper::handle`, when empty, show the right error message.

The error message currently says that `throw_exception` cannot be called on an empty `exception_wrapper`, but should say that `handle` cannot be called on an empty `exception_wrapper`.

Reviewed By: Orvid

Differential Revision: D5432380

fbshipit-source-id: ffa69c7675ee332e596e861e59ea273c39fc4717

folly/ExceptionWrapper-inl.h
folly/ExceptionWrapper.cpp
folly/ExceptionWrapper.h

index eca49ba6efcd3e6acf7532ee3ac885d44f3be10c..7a965525aee302cc0f1f154174bbb41de4a0198a 100644 (file)
@@ -459,7 +459,7 @@ inline bool exception_wrapper::is_compatible_with() const noexcept {
 
 [[noreturn]] inline void exception_wrapper::throw_exception() const {
   vptr_->throw_(this);
-  onNoExceptionError();
+  onNoExceptionError(__func__);
 }
 
 template <class CatchFn, bool IsConst>
@@ -645,7 +645,7 @@ inline void exception_wrapper::handle(CatchFns... fns) {
   using AllStdEx =
       exception_wrapper_detail::AllOf<IsStdException, arg_type<CatchFns>...>;
   if (!*this) {
-    onNoExceptionError();
+    onNoExceptionError(__func__);
   }
   this->handle_(AllStdEx{}, *this, fns...);
 }
@@ -654,7 +654,7 @@ inline void exception_wrapper::handle(CatchFns... fns) const {
   using AllStdEx =
       exception_wrapper_detail::AllOf<IsStdException, arg_type<CatchFns>...>;
   if (!*this) {
-    onNoExceptionError();
+    onNoExceptionError(__func__);
   }
   this->handle_(AllStdEx{}, *this, fns...);
 }
index 97713ed307eeb35087519b307a9e5cce00478048..205b0d78d71242c6f31e817de343fc09fab03a46 100644 (file)
@@ -76,11 +76,11 @@ exception_wrapper::exception_wrapper(std::exception_ptr ptr) noexcept
   }
 }
 
-[[noreturn]] void exception_wrapper::onNoExceptionError() {
+[[noreturn]] void exception_wrapper::onNoExceptionError(
+    char const* const name) {
   std::ios_base::Init ioinit_; // ensure std::cerr is alive
-  std::cerr
-      << "Cannot use `throw_exception` with an empty folly::exception_wrapper"
-      << std::endl;
+  std::cerr << "Cannot use `" << name
+            << "` with an empty folly::exception_wrapper" << std::endl;
   std::terminate();
 }
 
index d8b6a4d8b02b36d09dffc3de21f6122371fc312b..b932abb4cb5a585342a811b0fd6be9667584ad43 100644 (file)
@@ -197,7 +197,7 @@ class exception_wrapper final {
     exception_wrapper (*get_exception_ptr_)(exception_wrapper const*);
   };
 
-  [[noreturn]] static void onNoExceptionError();
+  [[noreturn]] static void onNoExceptionError(char const* name);
 
   template <class Ret, class... Args>
   static Ret noop_(Args...);