Casing consistency for exception_wrapper::throw_exception
authorYedidya Feldblum <yfeldblum@fb.com>
Thu, 27 Apr 2017 08:18:43 +0000 (01:18 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 27 Apr 2017 08:25:16 +0000 (01:25 -0700)
Summary: [Folly] Casing consistency for `exception_wrapper::throw_exception`.

Reviewed By: Orvid

Differential Revision: D4944818

fbshipit-source-id: 72056fb24ab6362e9a0319f73b5bbf8c92d658ca

folly/ExceptionWrapper-inl.h
folly/ExceptionWrapper.cpp
folly/ExceptionWrapper.h
folly/Try-inl.h
folly/futures/test/InterruptTest.cpp
folly/python/__init__.pxd
folly/python/test/simplebridge.pyx
folly/test/ExceptionWrapperBenchmark.cpp
folly/test/ExceptionWrapperTest.cpp

index 0de18b0c7aa5e2a464457db6b807818dbfcc9275..d0062bcacd0c570a9622ef7007c6041e8950f404 100644 (file)
@@ -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<std::is_const<This>::value>{&handled},
-      [&] { this_.throwException(); },
+      [&] { this_.throw_exception(); },
       fns...);
   impl();
 }
index 0079db866d7160f368b869983e22370c3210109c..97713ed307eeb35087519b307a9e5cce00478048 100644 (file)
@@ -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();
 }
index 9f734c5e8a738e0619becdcd8f334c1ad660f9b5..c305e688d79fa750b9e61bae02c0026750d2f07d 100644 (file)
@@ -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<std::exception, std::runtime_error>([=]() {
 //!   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<std::exception, std::runtime_error>([=]() {
 //!   if (badThingHappens()) {
index 522e77b984450604b40a77fb0d4602b4cdd4c20a..7411ec90308e99c874b2a9c2cd3eef8b9924ca9d 100644 (file)
@@ -122,7 +122,7 @@ template <class T>
 void Try<T>::throwIfFailed() const {
   if (contains_ != Contains::VALUE) {
     if (contains_ == Contains::EXCEPTION) {
-      e_->throwException();
+      e_->throw_exception();
     } else {
       throw UsingUninitializedTry();
     }
@@ -131,7 +131,7 @@ void Try<T>::throwIfFailed() const {
 
 void Try<void>::throwIfFailed() const {
   if (!hasValue_) {
-    e_->throwException();
+    e_->throw_exception();
   }
 }
 
index 4447dae6b78ce7d700e0f2cc460dffa0a8818bde..7e8f3298e407deb2c153d2a0aa637597e593db8d 100644 (file)
@@ -25,7 +25,7 @@ TEST(Interrupt, raise) {
   using eggs_t = std::runtime_error;
   Promise<Unit> 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<Unit> p;
   p.setInterruptHandler([&](const exception_wrapper& e) {
-    EXPECT_THROW(e.throwException(), FutureCancellation);
+    EXPECT_THROW(e.throw_exception(), FutureCancellation);
   });
   p.getFuture().cancel();
 }
index b45054c8b3d8968b394c89773655597ff2f45d87..d104b414a7eae090238b4e8dc504153d8147e59d 100644 (file)
@@ -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]:
index f697dff8ff66eebd8cdf9b50ee07c8c258f81e40..b8f7106e34086103ce8589e26632bef684fe9d59 100644 (file)
@@ -24,7 +24,7 @@ cdef void handle_uint64_t(cFollyTry[uint64_t]&& res, PyObject* userData):
     future = <object> userData
     if res.hasException():
         try:
-            res.exception().throwException()
+            res.exception().throw_exception()
         except Exception as ex:
             future.set_exception(ex)
     else:
index 16af2206bc03576970c0ae0b47c639a2de21f95c..dc52f5ce3e7510c3ce93f9b8add581b445550f97 100644 (file)
@@ -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<std::runtime_error>(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<std::runtime_error>(e);
           try {
-            ew.throwException();
+            ew.throw_exception();
           } catch (std::runtime_error&) {
           }
         }
index 91581586f143d495ed5bd5cc09075206bd2feaac..852f1f6fd3a9d108056d7aa7ef1e8cc4edc97a64 100644 (file)
@@ -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<std::runtime_error>(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<std::exception>());
   EXPECT_FALSE(ew.is_compatible_with<int>());
-  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<std::exception>());
   EXPECT_TRUE(ew.is_compatible_with<std::runtime_error>());
   EXPECT_FALSE(ew.is_compatible_with<int>());
-  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<std::exception>());
   EXPECT_TRUE(ew.is_compatible_with<std::runtime_error>());
   EXPECT_FALSE(ew.is_compatible_with<int>());
-  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<std::exception>());
   EXPECT_FALSE(ew.is_compatible_with<std::runtime_error>());
   EXPECT_TRUE(ew.is_compatible_with<int>());
-  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<std::exception>());
   EXPECT_FALSE(ew.is_compatible_with<std::runtime_error>());
   EXPECT_TRUE(ew.is_compatible_with<int>());
-  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<std::exception>());
   EXPECT_FALSE(ew.is_compatible_with<std::runtime_error>());
   EXPECT_TRUE(ew.is_compatible_with<int>());
-  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