From cea2cf9937ab5b8c6de3ec373f361bc805c12c21 Mon Sep 17 00:00:00 2001 From: Adam Malinowski Date: Fri, 25 Jul 2014 14:56:46 +0200 Subject: [PATCH] Fix implementation of what() method in Exception class Change-Id: Ib0259dbd85bc5526b474396ac82b819f0b03b54d --- src/common/exceptions/Exception.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common/exceptions/Exception.h b/src/common/exceptions/Exception.h index 92546b2..b709060 100644 --- a/src/common/exceptions/Exception.h +++ b/src/common/exceptions/Exception.h @@ -36,13 +36,17 @@ public: virtual ~Exception() = default; virtual const char *what(void) const noexcept { - return (message() + " From: " + m_backtrace).c_str(); + if(m_whatMessage.empty()) { + m_whatMessage = message() + " From: " + m_backtrace; + } + return m_whatMessage.c_str(); } virtual const std::string message(void) const = 0; private: std::string m_backtrace; + mutable std::string m_whatMessage; }; } /* namespace Cynara */ -- 2.7.4