aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2016-09-20 14:45:50 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2016-09-20 14:45:50 +0000
commitf4787b504e67005bbe8b7b8716b812514c4a5308 (patch)
tree8349b86543420175bcd405d32bb7d70d865acf3a /vespalib/src
parenta0588fd32d8457633b21ac19310727f2cb6fa432 (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.cpp13
-rw-r--r--vespalib/src/vespa/vespalib/util/exceptions.cpp5
-rw-r--r--vespalib/src/vespa/vespalib/util/exceptions.h1
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;