diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2016-09-20 14:45:50 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2016-09-20 14:45:50 +0000 |
commit | f4787b504e67005bbe8b7b8716b812514c4a5308 (patch) | |
tree | 8349b86543420175bcd405d32bb7d70d865acf3a /vespalib/src | |
parent | a0588fd32d8457633b21ac19310727f2cb6fa432 (diff) |
Provide the supplied message to the catch place.
Diffstat (limited to 'vespalib/src')
-rw-r--r-- | vespalib/src/tests/exception_classes/exception_classes_test.cpp | 13 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/exceptions.cpp | 5 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/exceptions.h | 1 |
3 files changed, 19 insertions, 0 deletions
diff --git a/vespalib/src/tests/exception_classes/exception_classes_test.cpp b/vespalib/src/tests/exception_classes/exception_classes_test.cpp index f9413970281..946c3fa32e4 100644 --- a/vespalib/src/tests/exception_classes/exception_classes_test.cpp +++ b/vespalib/src/tests/exception_classes/exception_classes_test.cpp @@ -33,4 +33,17 @@ TEST("require that PortListenException with cause retains relevant information") } } +TEST("test that OOMException carries message forward.") { + const char * M = "This is the simple message."; + bool caught(false); + try { + throw OOMException(M); + ASSERT_TRUE(false); + } catch (OOMException & e) { + EXPECT_EQUAL(0, strcmp(M, e.what())); + caught = true; + } + EXPECT_TRUE(caught); +} + TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/vespalib/src/vespa/vespalib/util/exceptions.cpp b/vespalib/src/vespa/vespalib/util/exceptions.cpp index ce1de7d569a..99485422493 100644 --- a/vespalib/src/vespa/vespalib/util/exceptions.cpp +++ b/vespalib/src/vespa/vespalib/util/exceptions.cpp @@ -39,6 +39,11 @@ void silent_terminate() { } +const char * +ExceptionWithPayload::what() const noexcept { + return _msg.c_str(); +} + SilenceUncaughtException::SilenceUncaughtException(const std::exception & e) : _oldTerminate(std::set_terminate(silent_terminate)) { diff --git a/vespalib/src/vespa/vespalib/util/exceptions.h b/vespalib/src/vespa/vespalib/util/exceptions.h index 721829e90d8..0fc0e96e193 100644 --- a/vespalib/src/vespa/vespalib/util/exceptions.h +++ b/vespalib/src/vespa/vespalib/util/exceptions.h @@ -71,6 +71,7 @@ public: ExceptionWithPayload(vespalib::stringref msg) : std::exception(), _msg(msg), _payload() { } ExceptionWithPayload(vespalib::stringref msg, Anything::UP payload) : std::exception(), _msg(msg), _payload(std::move(payload)) { } void setPayload(Anything::UP payload) { _payload = std::move(payload); } + const char * what() const noexcept override; private: vespalib::string _msg; Anything::UP _payload; |