Commit cd058f18 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Rename exception_wrapper::getExceptionPtr to to_exception_ptr

Summary:
[Folly] Rename `exception_wrapper::getExceptionPtr` to `to_exception_ptr`.

Make it clear that this will sometimes be an expensive operation. Using the word `to` evokes the possibility of an expensive conversion, while using the word `get` implies cheap access.

Reviewed By: djwatson

Differential Revision: D4391621

fbshipit-source-id: 33ca051d9be5a6050ba9f30b20faee35b7e58afb
parent 232f650c
......@@ -222,7 +222,7 @@ class exception_wrapper {
return with_exception1<_t<std::decay<Ex>>>(std::forward<F>(f), this);
}
std::exception_ptr getExceptionPtr() const {
std::exception_ptr to_exception_ptr() const {
if (eptr_) {
return eptr_;
}
......
......@@ -208,30 +208,30 @@ TEST(ExceptionWrapper, with_exception_test) {
*/
}
TEST(ExceptionWrapper, getExceptionPtr_test) {
TEST(ExceptionWrapper, get_or_make_exception_ptr_test) {
int expected = 23;
// This works, and doesn't slice.
exception_wrapper ew = try_and_catch<std::exception, std::runtime_error>(
[=]() { throw IntException(expected); });
std::exception_ptr eptr = ew.getExceptionPtr();
std::exception_ptr eptr = ew.to_exception_ptr();
EXPECT_THROW(std::rethrow_exception(eptr), IntException);
// I can try_and_catch a non-copyable base class. This will use
// std::exception_ptr internally.
exception_wrapper ew2 = try_and_catch<AbstractIntException>(
[=]() { throw IntException(expected); });
eptr = ew2.getExceptionPtr();
eptr = ew2.to_exception_ptr();
EXPECT_THROW(std::rethrow_exception(eptr), IntException);
// Test with const this.
const exception_wrapper& cew = ew;
eptr = cew.getExceptionPtr();
eptr = cew.to_exception_ptr();
EXPECT_THROW(std::rethrow_exception(eptr), IntException);
// Test with empty ew.
exception_wrapper empty_ew;
eptr = empty_ew.getExceptionPtr();
eptr = empty_ew.to_exception_ptr();
EXPECT_FALSE(eptr);
}
......
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