From: Yedidya Feldblum Date: Mon, 17 Jul 2017 05:07:08 +0000 (-0700) Subject: Let exception_wrapper::handle, when empty, show the right error message X-Git-Tag: v2017.07.17.00^0 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6139d03f90efd6d59f524d773db856d171a265ac;p=folly.git Let exception_wrapper::handle, when empty, show the right error message 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 --- diff --git a/folly/ExceptionWrapper-inl.h b/folly/ExceptionWrapper-inl.h index eca49ba6..7a965525 100644 --- a/folly/ExceptionWrapper-inl.h +++ b/folly/ExceptionWrapper-inl.h @@ -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 @@ -645,7 +645,7 @@ inline void exception_wrapper::handle(CatchFns... fns) { using AllStdEx = exception_wrapper_detail::AllOf...>; 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...>; if (!*this) { - onNoExceptionError(); + onNoExceptionError(__func__); } this->handle_(AllStdEx{}, *this, fns...); } diff --git a/folly/ExceptionWrapper.cpp b/folly/ExceptionWrapper.cpp index 97713ed3..205b0d78 100644 --- a/folly/ExceptionWrapper.cpp +++ b/folly/ExceptionWrapper.cpp @@ -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(); } diff --git a/folly/ExceptionWrapper.h b/folly/ExceptionWrapper.h index d8b6a4d8..b932abb4 100644 --- a/folly/ExceptionWrapper.h +++ b/folly/ExceptionWrapper.h @@ -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 static Ret noop_(Args...);