CodeMod: Use the ExceptionWrapper::with_exception variant that deduces exception...
authorYedidya Feldblum <yfeldblum@fb.com>
Tue, 1 Dec 2015 06:54:20 +0000 (22:54 -0800)
committerfacebook-github-bot-0 <folly-bot@fb.com>
Tue, 1 Dec 2015 07:20:20 +0000 (23:20 -0800)
Summary: CodeMod: Use the `ExceptionWrapper::with_exception` variant that deduces exception types.

Since we must specify the exception type in the lambda arg, and there is a variant of `ExceptionWrapper::with_exception` that deduces the type of the exception from the type of the lambda arg, we don't need to specify the exception type again as a template parameter anymore.

Reviewed By: meyering

Differential Revision: D2694895

fb-gh-sync-id: 505469f9008973a315e836f356e5db97df4ec921

folly/ExceptionWrapper.h
folly/futures/Try.h
folly/test/ExceptionWrapperTest.cpp

index f97f1a8ec2544824166b39ddd15f32fe6b418f99..7a5610b73bd4d6de1bdc58e012c446c139425b20 100644 (file)
@@ -89,11 +89,11 @@ namespace folly {
  * // Thread2: Exceptions are bad!
  * void processResult() {
  *   auto ep = globalExceptionWrapper.get();
- *   if (!ep.with_exception<FacePlantException>([&](
+ *   if (!ep.with_exception([&](
  *     FacePlantException& faceplant) {
  *       LOG(ERROR) << "FACEPLANT";
  *     })) {
- *     ep.with_exception<FailWhaleException>([&](
+ *     ep.with_exception([&](
  *       FailWhaleException& failwhale) {
  *         LOG(ERROR) << "FAILWHALE!";
  *       });
index beec20a24d8dbc8b1c9b88b155afd8710671b8dd..4aeea8fcbe0076d820b91375077015d13d0e064c 100644 (file)
@@ -209,7 +209,7 @@ class Try {
     if (!hasException()) {
       return false;
     }
-    return e_->with_exception<Ex>(std::move(func));
+    return e_->with_exception(std::move(func));
   }
 
   template <bool isTry, typename R>
@@ -329,7 +329,7 @@ class Try<void> {
     if (!hasException()) {
       return false;
     }
-    return e_->with_exception<Ex>(std::move(func));
+    return e_->with_exception(std::move(func));
   }
 
   template <bool, typename R>
index 265c5b02a5997fef53b2bcb31cb6d4ab808fcb88..74e2d0d314e8cde2c3973cafe316c3a80180a617 100644 (file)
@@ -162,7 +162,7 @@ TEST(ExceptionWrapper, with_exception_test) {
   EXPECT_TRUE(bool(ew));
   EXPECT_EQ(ew.what(), "IntException: int == 23");
   EXPECT_EQ(ew.class_name(), "IntException");
-  ew.with_exception<IntException>([&](const IntException& ie) {
+  ew.with_exception([&](const IntException& ie) {
       EXPECT_EQ(ie.getInt(), expected);
     });
 
@@ -175,7 +175,7 @@ TEST(ExceptionWrapper, with_exception_test) {
   EXPECT_TRUE(bool(ew2));
   EXPECT_EQ(ew2.what(), "IntException: int == 23");
   EXPECT_EQ(ew2.class_name(), "IntException");
-  ew2.with_exception<AbstractIntException>([&](AbstractIntException& ie) {
+  ew2.with_exception([&](AbstractIntException& ie) {
       EXPECT_EQ(ie.getInt(), expected);
 #if __CLANG_PREREQ(3, 6)
 # pragma clang diagnostic push
@@ -190,14 +190,14 @@ TEST(ExceptionWrapper, with_exception_test) {
   // Test with const this.  If this compiles and does not crash due to
   // infinite loop when it runs, it succeeds.
   const exception_wrapper& cew = ew;
-  cew.with_exception<IntException>([&](const IntException& ie) {
+  cew.with_exception([&](const IntException& ie) {
       SUCCEED();
     });
 
   // This won't even compile.  You can't use a function which takes a
   // non-const reference with a const exception_wrapper.
 /*
-  cew.with_exception<IntException>([&](IntException& ie) {
+  cew.with_exception([&](IntException& ie) {
       SUCCEED();
     });
 */