From d2efd8104d4191f67140ecdbd5343ba05552f083 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Thu, 27 Apr 2017 01:18:43 -0700 Subject: [PATCH] Casing consistency for exception_wrapper::throw_exception Summary: [Folly] Casing consistency for `exception_wrapper::throw_exception`. Reviewed By: Orvid Differential Revision: D4944818 fbshipit-source-id: 72056fb24ab6362e9a0319f73b5bbf8c92d658ca --- folly/ExceptionWrapper-inl.h | 4 ++-- folly/ExceptionWrapper.cpp | 2 +- folly/ExceptionWrapper.h | 15 ++++++++++----- folly/Try-inl.h | 4 ++-- folly/futures/test/InterruptTest.cpp | 4 ++-- folly/python/__init__.pxd | 2 +- folly/python/test/simplebridge.pyx | 2 +- folly/test/ExceptionWrapperBenchmark.cpp | 4 ++-- folly/test/ExceptionWrapperTest.cpp | 22 +++++++++++----------- 9 files changed, 32 insertions(+), 27 deletions(-) diff --git a/folly/ExceptionWrapper-inl.h b/folly/ExceptionWrapper-inl.h index 0de18b0c..d0062bca 100644 --- a/folly/ExceptionWrapper-inl.h +++ b/folly/ExceptionWrapper-inl.h @@ -383,7 +383,7 @@ inline bool exception_wrapper::is_compatible_with() const noexcept { return with_exception([](Ex const&) {}); } -[[noreturn]] inline void exception_wrapper::throwException() const { +[[noreturn]] inline void exception_wrapper::throw_exception() const { vptr_->throw_(this); onNoExceptionError(); } @@ -498,7 +498,7 @@ inline void exception_wrapper::handle_( bool handled = false; auto impl = exception_wrapper_detail::fold( HandleReduce::value>{&handled}, - [&] { this_.throwException(); }, + [&] { this_.throw_exception(); }, fns...); impl(); } diff --git a/folly/ExceptionWrapper.cpp b/folly/ExceptionWrapper.cpp index 0079db86..97713ed3 100644 --- a/folly/ExceptionWrapper.cpp +++ b/folly/ExceptionWrapper.cpp @@ -79,7 +79,7 @@ exception_wrapper::exception_wrapper(std::exception_ptr ptr) noexcept [[noreturn]] void exception_wrapper::onNoExceptionError() { std::ios_base::Init ioinit_; // ensure std::cerr is alive std::cerr - << "Cannot use `throwException` with an empty folly::exception_wrapper" + << "Cannot use `throw_exception` with an empty folly::exception_wrapper" << std::endl; std::terminate(); } diff --git a/folly/ExceptionWrapper.h b/folly/ExceptionWrapper.h index 9f734c5e..c305e688 100644 --- a/folly/ExceptionWrapper.h +++ b/folly/ExceptionWrapper.h @@ -137,7 +137,7 @@ auto fold(Fn&& fn, A&& a, B&& b, Bs&&... bs) { //! // Thread2: Exceptions are ok! //! void processResult() { //! try { -//! globalExceptionWrapper.throwException(); +//! globalExceptionWrapper.throw_exception(); //! } catch (const FacePlantException& e) { //! LOG(ERROR) << "FACEPLANT!"; //! } catch (const FailWhaleException& e) { @@ -499,7 +499,12 @@ class exception_wrapper final { //! \pre `bool(*this)` //! Throws the wrapped expression. - [[noreturn]] void throwException() const; + [[noreturn]] void throw_exception() const; + + [[noreturn]] FOLLY_DEPRECATED( + "use throw_exception") void throwException() const { + throw_exception(); + } //! Call `fn` with the wrapped exception (if any), if `fn` can accept it. //! \par Example @@ -542,7 +547,7 @@ class exception_wrapper final { //! ew.handle( //! [&](std::logic_error const& e) { //! LOG(DFATAL) << "ruh roh"; - //! ew.throwException(); // rethrow the active exception without + //! ew.throw_exception(); // rethrow the active exception without //! // slicing it. Will not be caught by other //! // handlers in this call. //! }, @@ -634,7 +639,7 @@ inline exception_wrapper try_and_catch_(F&& f) { //! //! \par Example Usage: //! \code -//! // This catches my runtime_error and if I call throwException() on ew, it +//! // This catches my runtime_error and if I call throw_exception() on ew, it //! // will throw a runtime_error //! auto ew = folly::try_and_catch([=]() { //! if (badThingHappens()) { @@ -642,7 +647,7 @@ inline exception_wrapper try_and_catch_(F&& f) { //! } //! }); //! -//! // This will catch the exception and if I call throwException() on ew, it +//! // This will catch the exception and if I call throw_exception() on ew, it //! // will throw a std::exception //! auto ew = folly::try_and_catch([=]() { //! if (badThingHappens()) { diff --git a/folly/Try-inl.h b/folly/Try-inl.h index 522e77b9..7411ec90 100644 --- a/folly/Try-inl.h +++ b/folly/Try-inl.h @@ -122,7 +122,7 @@ template void Try::throwIfFailed() const { if (contains_ != Contains::VALUE) { if (contains_ == Contains::EXCEPTION) { - e_->throwException(); + e_->throw_exception(); } else { throw UsingUninitializedTry(); } @@ -131,7 +131,7 @@ void Try::throwIfFailed() const { void Try::throwIfFailed() const { if (!hasValue_) { - e_->throwException(); + e_->throw_exception(); } } diff --git a/folly/futures/test/InterruptTest.cpp b/folly/futures/test/InterruptTest.cpp index 4447dae6..7e8f3298 100644 --- a/folly/futures/test/InterruptTest.cpp +++ b/folly/futures/test/InterruptTest.cpp @@ -25,7 +25,7 @@ TEST(Interrupt, raise) { using eggs_t = std::runtime_error; Promise p; p.setInterruptHandler([&](const exception_wrapper& e) { - EXPECT_THROW(e.throwException(), eggs_t); + EXPECT_THROW(e.throw_exception(), eggs_t); }); p.getFuture().raise(eggs_t("eggs")); } @@ -33,7 +33,7 @@ TEST(Interrupt, raise) { TEST(Interrupt, cancel) { Promise p; p.setInterruptHandler([&](const exception_wrapper& e) { - EXPECT_THROW(e.throwException(), FutureCancellation); + EXPECT_THROW(e.throw_exception(), FutureCancellation); }); p.getFuture().cancel(); } diff --git a/folly/python/__init__.pxd b/folly/python/__init__.pxd index b45054c8..d104b414 100644 --- a/folly/python/__init__.pxd +++ b/folly/python/__init__.pxd @@ -2,7 +2,7 @@ from libcpp cimport bool as cbool cdef extern from "folly/ExceptionWrapper.h" namespace "folly": cdef cppclass cFollyExceptionWrapper "folly::exception_wrapper": - void throwException() except + + void throw_exception() except + cdef extern from "folly/Try.h" namespace "folly" nogil: cdef cppclass cFollyTry "folly::Try"[T]: diff --git a/folly/python/test/simplebridge.pyx b/folly/python/test/simplebridge.pyx index f697dff8..b8f7106e 100644 --- a/folly/python/test/simplebridge.pyx +++ b/folly/python/test/simplebridge.pyx @@ -24,7 +24,7 @@ cdef void handle_uint64_t(cFollyTry[uint64_t]&& res, PyObject* userData): future = userData if res.hasException(): try: - res.exception().throwException() + res.exception().throw_exception() except Exception as ex: future.set_exception(ex) else: diff --git a/folly/test/ExceptionWrapperBenchmark.cpp b/folly/test/ExceptionWrapperBenchmark.cpp index 16af2206..dc52f5ce 100644 --- a/folly/test/ExceptionWrapperBenchmark.cpp +++ b/folly/test/ExceptionWrapperBenchmark.cpp @@ -119,7 +119,7 @@ BENCHMARK_RELATIVE(exception_wrapper_create_and_throw, iters) { for (size_t i = 0; i < iters; ++i) { auto ew = folly::make_exception_wrapper(e); try { - ew.throwException(); + ew.throw_exception(); } catch (std::runtime_error&) { } } @@ -172,7 +172,7 @@ BENCHMARK_RELATIVE(exception_wrapper_create_and_throw_concurrent, iters) { for (size_t i = 0; i < iters; ++i) { auto ew = folly::make_exception_wrapper(e); try { - ew.throwException(); + ew.throw_exception(); } catch (std::runtime_error&) { } } diff --git a/folly/test/ExceptionWrapperTest.cpp b/folly/test/ExceptionWrapperTest.cpp index 91581586..852f1f6f 100644 --- a/folly/test/ExceptionWrapperTest.cpp +++ b/folly/test/ExceptionWrapperTest.cpp @@ -61,7 +61,7 @@ T& from_eptr(std::exception_ptr& eptr) { } } -// Tests that when we call throwException, the proper type is thrown (derived) +// Tests that when we call throw_exception, the proper type is thrown (derived) TEST(ExceptionWrapper, throw_test) { std::runtime_error e("payload"); auto ew = make_exception_wrapper(e); @@ -70,7 +70,7 @@ TEST(ExceptionWrapper, throw_test) { container.push_back(ew); try { - container[0].throwException(); + container[0].throw_exception(); } catch (std::runtime_error& err) { std::string expected = "payload"; std::string actual = err.what(); @@ -222,7 +222,7 @@ TEST(ExceptionWrapper, with_exception_ptr_empty) { EXPECT_EQ("", ew.what()); EXPECT_FALSE(ew.is_compatible_with()); EXPECT_FALSE(ew.is_compatible_with()); - EXPECT_DEATH(ew.throwException(), "empty folly::exception_wrapper"); + EXPECT_DEATH(ew.throw_exception(), "empty folly::exception_wrapper"); } TEST(ExceptionWrapper, with_shared_ptr_test) { @@ -238,7 +238,7 @@ TEST(ExceptionWrapper, with_shared_ptr_test) { EXPECT_TRUE(ew.is_compatible_with()); EXPECT_TRUE(ew.is_compatible_with()); EXPECT_FALSE(ew.is_compatible_with()); - EXPECT_THROW(ew.throwException(), std::runtime_error); + EXPECT_THROW(ew.throw_exception(), std::runtime_error); exception_wrapper(std::move(ew)); EXPECT_FALSE(bool(ew)); @@ -266,7 +266,7 @@ TEST(ExceptionWrapper, with_exception_ptr_exn_test) { EXPECT_TRUE(ew.is_compatible_with()); EXPECT_TRUE(ew.is_compatible_with()); EXPECT_FALSE(ew.is_compatible_with()); - EXPECT_THROW(ew.throwException(), std::runtime_error); + EXPECT_THROW(ew.throw_exception(), std::runtime_error); exception_wrapper(std::move(ew)); EXPECT_FALSE(bool(ew)); @@ -293,7 +293,7 @@ TEST(ExceptionWrapper, with_exception_ptr_any_test) { EXPECT_FALSE(ew.is_compatible_with()); EXPECT_FALSE(ew.is_compatible_with()); EXPECT_TRUE(ew.is_compatible_with()); - EXPECT_THROW(ew.throwException(), int); + EXPECT_THROW(ew.throw_exception(), int); exception_wrapper(std::move(ew)); EXPECT_FALSE(bool(ew)); @@ -321,7 +321,7 @@ TEST(ExceptionWrapper, with_non_std_exception_test) { EXPECT_FALSE(ew.is_compatible_with()); EXPECT_FALSE(ew.is_compatible_with()); EXPECT_TRUE(ew.is_compatible_with()); - EXPECT_THROW(ew.throwException(), int); + EXPECT_THROW(ew.throw_exception(), int); exception_wrapper(std::move(ew)); EXPECT_FALSE(bool(ew)); @@ -347,7 +347,7 @@ TEST(ExceptionWrapper, with_exception_ptr_any_nil_test) { EXPECT_FALSE(ew.is_compatible_with()); EXPECT_FALSE(ew.is_compatible_with()); EXPECT_TRUE(ew.is_compatible_with()); - EXPECT_THROW(ew.throwException(), int); + EXPECT_THROW(ew.throw_exception(), int); exception_wrapper(std::move(ew)); EXPECT_FALSE(bool(ew)); @@ -415,7 +415,7 @@ TEST(ExceptionWrapper, non_std_exception_test) { // non-std::exception types are supported, but the only way to // access their value is to explicity rethrow and catch it. try { - ew.throwException(); + ew.throw_exception(); } catch /* nolint */ (int& i) { EXPECT_EQ(i, expected); } @@ -429,13 +429,13 @@ TEST(ExceptionWrapper, exceptionStr) { TEST(ExceptionWrapper, throwException_noException) { exception_wrapper ew; - ASSERT_DEATH(ew.throwException(), "empty folly::exception_wrapper"); + ASSERT_DEATH(ew.throw_exception(), "empty folly::exception_wrapper"); } namespace { class TestException : public std::exception { }; void testEW(const exception_wrapper& ew) { - EXPECT_THROW(ew.throwException(), TestException); + EXPECT_THROW(ew.throw_exception(), TestException); } } // namespace -- 2.34.1