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

Rename exception_wrapper::get_object to get_exception

Summary:
[Folly] Rename `exception_wrapper::get_object` to `get_exception`.

This will be a template overload of the existing non-template member `get_exception`, but it should just work.

Reviewed By: spacedentist

Differential Revision: D5180845

fbshipit-source-id: 28e16e039ec6a7939b38f217b4ad5c6bc803f515
parent 3396d608
...@@ -351,14 +351,14 @@ inline std::exception const* exception_wrapper::get_exception() const noexcept { ...@@ -351,14 +351,14 @@ inline std::exception const* exception_wrapper::get_exception() const noexcept {
} }
template <typename Ex> template <typename Ex>
inline Ex* exception_wrapper::get_object() noexcept { inline Ex* exception_wrapper::get_exception() noexcept {
Ex* object{nullptr}; Ex* object{nullptr};
with_exception([&](Ex& ex) { object = &ex; }); with_exception([&](Ex& ex) { object = &ex; });
return object; return object;
} }
template <typename Ex> template <typename Ex>
inline Ex const* exception_wrapper::get_object() const noexcept { inline Ex const* exception_wrapper::get_exception() const noexcept {
Ex const* object{nullptr}; Ex const* object{nullptr};
with_exception([&](Ex const& ex) { object = &ex; }); with_exception([&](Ex const& ex) { object = &ex; });
return object; return object;
......
...@@ -464,10 +464,10 @@ class exception_wrapper final { ...@@ -464,10 +464,10 @@ class exception_wrapper final {
//! \note This function may cause an exception to be thrown and immediately //! \note This function may cause an exception to be thrown and immediately
//! caught internally, affecting runtime performance. //! caught internally, affecting runtime performance.
template <typename Ex> template <typename Ex>
Ex* get_object() noexcept; Ex* get_exception() noexcept;
//! \overload //! \overload
template <typename Ex> template <typename Ex>
Ex const* get_object() const noexcept; Ex const* get_exception() const noexcept;
//! \return A `std::exception_ptr` that references either the exception held //! \return A `std::exception_ptr` that references either the exception held
//! by `*this`, or a copy of same. //! by `*this`, or a copy of same.
......
...@@ -215,8 +215,8 @@ TEST(ExceptionWrapper, with_exception_ptr_empty) { ...@@ -215,8 +215,8 @@ TEST(ExceptionWrapper, with_exception_ptr_empty) {
EXPECT_EQ(exception_wrapper::none(), ew.type()); EXPECT_EQ(exception_wrapper::none(), ew.type());
EXPECT_FALSE(bool(ew)); EXPECT_FALSE(bool(ew));
EXPECT_EQ(nullptr, ew.get_exception()); EXPECT_EQ(nullptr, ew.get_exception());
EXPECT_EQ(nullptr, ew.get_object<std::exception>()); EXPECT_EQ(nullptr, ew.get_exception<std::exception>());
EXPECT_EQ(nullptr, ew.get_object<int>()); EXPECT_EQ(nullptr, ew.get_exception<int>());
EXPECT_FALSE(ew.has_exception_ptr()); EXPECT_FALSE(ew.has_exception_ptr());
EXPECT_EQ(nullptr, ew.to_exception_ptr()); EXPECT_EQ(nullptr, ew.to_exception_ptr());
EXPECT_FALSE(ew.has_exception_ptr()); EXPECT_FALSE(ew.has_exception_ptr());
...@@ -232,8 +232,8 @@ TEST(ExceptionWrapper, with_shared_ptr_test) { ...@@ -232,8 +232,8 @@ TEST(ExceptionWrapper, with_shared_ptr_test) {
EXPECT_TRUE(bool(ew)); EXPECT_TRUE(bool(ew));
EXPECT_EQ(typeid(std::runtime_error), ew.type()); EXPECT_EQ(typeid(std::runtime_error), ew.type());
EXPECT_NE(nullptr, ew.get_exception()); EXPECT_NE(nullptr, ew.get_exception());
EXPECT_NE(nullptr, ew.get_object<std::exception>()); EXPECT_NE(nullptr, ew.get_exception<std::exception>());
EXPECT_EQ(nullptr, ew.get_object<int>()); EXPECT_EQ(nullptr, ew.get_exception<int>());
EXPECT_FALSE(ew.has_exception_ptr()); EXPECT_FALSE(ew.has_exception_ptr());
EXPECT_NE(nullptr, ew.to_exception_ptr()); EXPECT_NE(nullptr, ew.to_exception_ptr());
EXPECT_TRUE(ew.has_exception_ptr()); EXPECT_TRUE(ew.has_exception_ptr());
...@@ -248,8 +248,8 @@ TEST(ExceptionWrapper, with_shared_ptr_test) { ...@@ -248,8 +248,8 @@ TEST(ExceptionWrapper, with_shared_ptr_test) {
EXPECT_FALSE(bool(ew)); EXPECT_FALSE(bool(ew));
EXPECT_EQ(exception_wrapper::none(), ew.type()); EXPECT_EQ(exception_wrapper::none(), ew.type());
EXPECT_EQ(nullptr, ew.get_exception()); EXPECT_EQ(nullptr, ew.get_exception());
EXPECT_EQ(nullptr, ew.get_object<std::exception>()); EXPECT_EQ(nullptr, ew.get_exception<std::exception>());
EXPECT_EQ(nullptr, ew.get_object<int>()); EXPECT_EQ(nullptr, ew.get_exception<int>());
EXPECT_EQ(nullptr, ew.to_exception_ptr()); EXPECT_EQ(nullptr, ew.to_exception_ptr());
EXPECT_EQ("", ew.class_name()); EXPECT_EQ("", ew.class_name());
EXPECT_EQ("", ew.what()); EXPECT_EQ("", ew.what());
...@@ -264,8 +264,8 @@ TEST(ExceptionWrapper, with_exception_ptr_exn_test) { ...@@ -264,8 +264,8 @@ TEST(ExceptionWrapper, with_exception_ptr_exn_test) {
EXPECT_TRUE(bool(ew)); EXPECT_TRUE(bool(ew));
EXPECT_EQ(typeid(std::runtime_error), ew.type()); EXPECT_EQ(typeid(std::runtime_error), ew.type());
EXPECT_NE(nullptr, ew.get_exception()); EXPECT_NE(nullptr, ew.get_exception());
EXPECT_NE(nullptr, ew.get_object<std::exception>()); EXPECT_NE(nullptr, ew.get_exception<std::exception>());
EXPECT_EQ(nullptr, ew.get_object<int>()); EXPECT_EQ(nullptr, ew.get_exception<int>());
EXPECT_TRUE(ew.has_exception_ptr()); EXPECT_TRUE(ew.has_exception_ptr());
EXPECT_EQ(ep, ew.to_exception_ptr()); EXPECT_EQ(ep, ew.to_exception_ptr());
EXPECT_TRUE(ew.has_exception_ptr()); EXPECT_TRUE(ew.has_exception_ptr());
...@@ -280,8 +280,8 @@ TEST(ExceptionWrapper, with_exception_ptr_exn_test) { ...@@ -280,8 +280,8 @@ TEST(ExceptionWrapper, with_exception_ptr_exn_test) {
EXPECT_FALSE(bool(ew)); EXPECT_FALSE(bool(ew));
EXPECT_EQ(exception_wrapper::none(), ew.type()); EXPECT_EQ(exception_wrapper::none(), ew.type());
EXPECT_EQ(nullptr, ew.get_exception()); EXPECT_EQ(nullptr, ew.get_exception());
EXPECT_EQ(nullptr, ew.get_object<std::exception>()); EXPECT_EQ(nullptr, ew.get_exception<std::exception>());
EXPECT_EQ(nullptr, ew.get_object<int>()); EXPECT_EQ(nullptr, ew.get_exception<int>());
EXPECT_EQ(nullptr, ew.to_exception_ptr()); EXPECT_EQ(nullptr, ew.to_exception_ptr());
EXPECT_EQ("", ew.class_name()); EXPECT_EQ("", ew.class_name());
EXPECT_EQ("", ew.what()); EXPECT_EQ("", ew.what());
...@@ -295,8 +295,8 @@ TEST(ExceptionWrapper, with_exception_ptr_any_test) { ...@@ -295,8 +295,8 @@ TEST(ExceptionWrapper, with_exception_ptr_any_test) {
auto ew = exception_wrapper(ep, from_eptr<int>(ep)); auto ew = exception_wrapper(ep, from_eptr<int>(ep));
EXPECT_TRUE(bool(ew)); EXPECT_TRUE(bool(ew));
EXPECT_EQ(nullptr, ew.get_exception()); EXPECT_EQ(nullptr, ew.get_exception());
EXPECT_EQ(nullptr, ew.get_object<std::exception>()); EXPECT_EQ(nullptr, ew.get_exception<std::exception>());
EXPECT_NE(nullptr, ew.get_object<int>()); EXPECT_NE(nullptr, ew.get_exception<int>());
EXPECT_TRUE(ew.has_exception_ptr()); EXPECT_TRUE(ew.has_exception_ptr());
EXPECT_EQ(ep, ew.to_exception_ptr()); EXPECT_EQ(ep, ew.to_exception_ptr());
EXPECT_TRUE(ew.has_exception_ptr()); EXPECT_TRUE(ew.has_exception_ptr());
...@@ -310,8 +310,8 @@ TEST(ExceptionWrapper, with_exception_ptr_any_test) { ...@@ -310,8 +310,8 @@ TEST(ExceptionWrapper, with_exception_ptr_any_test) {
exception_wrapper(std::move(ew)); exception_wrapper(std::move(ew));
EXPECT_FALSE(bool(ew)); EXPECT_FALSE(bool(ew));
EXPECT_EQ(nullptr, ew.get_exception()); EXPECT_EQ(nullptr, ew.get_exception());
EXPECT_EQ(nullptr, ew.get_object<std::exception>()); EXPECT_EQ(nullptr, ew.get_exception<std::exception>());
EXPECT_EQ(nullptr, ew.get_object<int>()); EXPECT_EQ(nullptr, ew.get_exception<int>());
EXPECT_EQ(nullptr, ew.to_exception_ptr()); EXPECT_EQ(nullptr, ew.to_exception_ptr());
EXPECT_FALSE(ew.has_exception_ptr()); EXPECT_FALSE(ew.has_exception_ptr());
EXPECT_EQ("", ew.class_name()); EXPECT_EQ("", ew.class_name());
...@@ -325,8 +325,8 @@ TEST(ExceptionWrapper, with_non_std_exception_test) { ...@@ -325,8 +325,8 @@ TEST(ExceptionWrapper, with_non_std_exception_test) {
auto ew = exception_wrapper(folly::in_place, 42); auto ew = exception_wrapper(folly::in_place, 42);
EXPECT_TRUE(bool(ew)); EXPECT_TRUE(bool(ew));
EXPECT_EQ(nullptr, ew.get_exception()); EXPECT_EQ(nullptr, ew.get_exception());
EXPECT_EQ(nullptr, ew.get_object<std::exception>()); EXPECT_EQ(nullptr, ew.get_exception<std::exception>());
EXPECT_NE(nullptr, ew.get_object<int>()); EXPECT_NE(nullptr, ew.get_exception<int>());
EXPECT_FALSE(ew.has_exception_ptr()); EXPECT_FALSE(ew.has_exception_ptr());
EXPECT_EQ("int", ew.class_name()); EXPECT_EQ("int", ew.class_name());
EXPECT_EQ("int", ew.what()); EXPECT_EQ("int", ew.what());
...@@ -342,8 +342,8 @@ TEST(ExceptionWrapper, with_non_std_exception_test) { ...@@ -342,8 +342,8 @@ TEST(ExceptionWrapper, with_non_std_exception_test) {
exception_wrapper(std::move(ew)); exception_wrapper(std::move(ew));
EXPECT_FALSE(bool(ew)); EXPECT_FALSE(bool(ew));
EXPECT_EQ(nullptr, ew.get_exception()); EXPECT_EQ(nullptr, ew.get_exception());
EXPECT_EQ(nullptr, ew.get_object<std::exception>()); EXPECT_EQ(nullptr, ew.get_exception<std::exception>());
EXPECT_EQ(nullptr, ew.get_object<int>()); EXPECT_EQ(nullptr, ew.get_exception<int>());
EXPECT_EQ(nullptr, ew.to_exception_ptr()); EXPECT_EQ(nullptr, ew.to_exception_ptr());
EXPECT_FALSE(ew.has_exception_ptr()); EXPECT_FALSE(ew.has_exception_ptr());
EXPECT_EQ("", ew.class_name()); EXPECT_EQ("", ew.class_name());
...@@ -358,8 +358,8 @@ TEST(ExceptionWrapper, with_exception_ptr_any_nil_test) { ...@@ -358,8 +358,8 @@ TEST(ExceptionWrapper, with_exception_ptr_any_nil_test) {
auto ew = exception_wrapper(ep); // concrete type is erased auto ew = exception_wrapper(ep); // concrete type is erased
EXPECT_TRUE(bool(ew)); EXPECT_TRUE(bool(ew));
EXPECT_EQ(nullptr, ew.get_exception()); EXPECT_EQ(nullptr, ew.get_exception());
EXPECT_EQ(nullptr, ew.get_object<std::exception>()); EXPECT_EQ(nullptr, ew.get_exception<std::exception>());
EXPECT_NE(nullptr, ew.get_object<int>()); EXPECT_NE(nullptr, ew.get_exception<int>());
EXPECT_EQ(ep, ew.to_exception_ptr()); EXPECT_EQ(ep, ew.to_exception_ptr());
EXPECT_EQ("<unknown exception>", ew.class_name()); // because concrete type is EXPECT_EQ("<unknown exception>", ew.class_name()); // because concrete type is
// erased // erased
...@@ -372,8 +372,8 @@ TEST(ExceptionWrapper, with_exception_ptr_any_nil_test) { ...@@ -372,8 +372,8 @@ TEST(ExceptionWrapper, with_exception_ptr_any_nil_test) {
exception_wrapper(std::move(ew)); exception_wrapper(std::move(ew));
EXPECT_FALSE(bool(ew)); EXPECT_FALSE(bool(ew));
EXPECT_EQ(nullptr, ew.get_exception()); EXPECT_EQ(nullptr, ew.get_exception());
EXPECT_EQ(nullptr, ew.get_object<std::exception>()); EXPECT_EQ(nullptr, ew.get_exception<std::exception>());
EXPECT_EQ(nullptr, ew.get_object<int>()); EXPECT_EQ(nullptr, ew.get_exception<int>());
EXPECT_EQ(nullptr, ew.to_exception_ptr()); EXPECT_EQ(nullptr, ew.to_exception_ptr());
EXPECT_EQ("", ew.class_name()); EXPECT_EQ("", ew.class_name());
EXPECT_EQ("", ew.what()); EXPECT_EQ("", ew.what());
......
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