Commit 15e17fa2 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by facebook-github-bot-0

CodeMod: Use the ExceptionWrapper::with_exception variant that deduces exception types

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
parent 8d56fe68
...@@ -89,11 +89,11 @@ namespace folly { ...@@ -89,11 +89,11 @@ namespace folly {
* // Thread2: Exceptions are bad! * // Thread2: Exceptions are bad!
* void processResult() { * void processResult() {
* auto ep = globalExceptionWrapper.get(); * auto ep = globalExceptionWrapper.get();
* if (!ep.with_exception<FacePlantException>([&]( * if (!ep.with_exception([&](
* FacePlantException& faceplant) { * FacePlantException& faceplant) {
* LOG(ERROR) << "FACEPLANT"; * LOG(ERROR) << "FACEPLANT";
* })) { * })) {
* ep.with_exception<FailWhaleException>([&]( * ep.with_exception([&](
* FailWhaleException& failwhale) { * FailWhaleException& failwhale) {
* LOG(ERROR) << "FAILWHALE!"; * LOG(ERROR) << "FAILWHALE!";
* }); * });
......
...@@ -209,7 +209,7 @@ class Try { ...@@ -209,7 +209,7 @@ class Try {
if (!hasException()) { if (!hasException()) {
return false; return false;
} }
return e_->with_exception<Ex>(std::move(func)); return e_->with_exception(std::move(func));
} }
template <bool isTry, typename R> template <bool isTry, typename R>
...@@ -329,7 +329,7 @@ class Try<void> { ...@@ -329,7 +329,7 @@ class Try<void> {
if (!hasException()) { if (!hasException()) {
return false; return false;
} }
return e_->with_exception<Ex>(std::move(func)); return e_->with_exception(std::move(func));
} }
template <bool, typename R> template <bool, typename R>
......
...@@ -162,7 +162,7 @@ TEST(ExceptionWrapper, with_exception_test) { ...@@ -162,7 +162,7 @@ TEST(ExceptionWrapper, with_exception_test) {
EXPECT_TRUE(bool(ew)); EXPECT_TRUE(bool(ew));
EXPECT_EQ(ew.what(), "IntException: int == 23"); EXPECT_EQ(ew.what(), "IntException: int == 23");
EXPECT_EQ(ew.class_name(), "IntException"); EXPECT_EQ(ew.class_name(), "IntException");
ew.with_exception<IntException>([&](const IntException& ie) { ew.with_exception([&](const IntException& ie) {
EXPECT_EQ(ie.getInt(), expected); EXPECT_EQ(ie.getInt(), expected);
}); });
...@@ -175,7 +175,7 @@ TEST(ExceptionWrapper, with_exception_test) { ...@@ -175,7 +175,7 @@ TEST(ExceptionWrapper, with_exception_test) {
EXPECT_TRUE(bool(ew2)); EXPECT_TRUE(bool(ew2));
EXPECT_EQ(ew2.what(), "IntException: int == 23"); EXPECT_EQ(ew2.what(), "IntException: int == 23");
EXPECT_EQ(ew2.class_name(), "IntException"); EXPECT_EQ(ew2.class_name(), "IntException");
ew2.with_exception<AbstractIntException>([&](AbstractIntException& ie) { ew2.with_exception([&](AbstractIntException& ie) {
EXPECT_EQ(ie.getInt(), expected); EXPECT_EQ(ie.getInt(), expected);
#if __CLANG_PREREQ(3, 6) #if __CLANG_PREREQ(3, 6)
# pragma clang diagnostic push # pragma clang diagnostic push
...@@ -190,14 +190,14 @@ TEST(ExceptionWrapper, with_exception_test) { ...@@ -190,14 +190,14 @@ TEST(ExceptionWrapper, with_exception_test) {
// Test with const this. If this compiles and does not crash due to // Test with const this. If this compiles and does not crash due to
// infinite loop when it runs, it succeeds. // infinite loop when it runs, it succeeds.
const exception_wrapper& cew = ew; const exception_wrapper& cew = ew;
cew.with_exception<IntException>([&](const IntException& ie) { cew.with_exception([&](const IntException& ie) {
SUCCEED(); SUCCEED();
}); });
// This won't even compile. You can't use a function which takes a // This won't even compile. You can't use a function which takes a
// non-const reference with a const exception_wrapper. // non-const reference with a const exception_wrapper.
/* /*
cew.with_exception<IntException>([&](IntException& ie) { cew.with_exception([&](IntException& ie) {
SUCCEED(); SUCCEED();
}); });
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment