return with_exception([](Ex const&) {});
}
-[[noreturn]] inline void exception_wrapper::throwException() const {
+[[noreturn]] inline void exception_wrapper::throw_exception() const {
vptr_->throw_(this);
onNoExceptionError();
}
bool handled = false;
auto impl = exception_wrapper_detail::fold(
HandleReduce<std::is_const<This>::value>{&handled},
- [&] { this_.throwException(); },
+ [&] { this_.throw_exception(); },
fns...);
impl();
}
[[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();
}
//! // Thread2: Exceptions are ok!
//! void processResult() {
//! try {
-//! globalExceptionWrapper.throwException();
+//! globalExceptionWrapper.throw_exception();
//! } catch (const FacePlantException& e) {
//! LOG(ERROR) << "FACEPLANT!";
//! } catch (const FailWhaleException& e) {
//! \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
//! 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.
//! },
//!
//! \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()) {
//! }
//! });
//!
-//! // 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()) {
void Try<T>::throwIfFailed() const {
if (contains_ != Contains::VALUE) {
if (contains_ == Contains::EXCEPTION) {
- e_->throwException();
+ e_->throw_exception();
} else {
throw UsingUninitializedTry();
}
void Try<void>::throwIfFailed() const {
if (!hasValue_) {
- e_->throwException();
+ e_->throw_exception();
}
}
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"));
}
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();
}
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]:
future = <object> userData
if res.hasException():
try:
- res.exception().throwException()
+ res.exception().throw_exception()
except Exception as ex:
future.set_exception(ex)
else:
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&) {
}
}
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&) {
}
}
}
}
-// 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);
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();
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) {
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));
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));
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));
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));
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));
// 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);
}
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