diff --git a/src/storm/exceptions/BaseException.cpp b/src/storm/exceptions/BaseException.cpp index 626231487..86119f600 100644 --- a/src/storm/exceptions/BaseException.cpp +++ b/src/storm/exceptions/BaseException.cpp @@ -19,11 +19,8 @@ namespace storm { } const char* BaseException::what() const NOEXCEPT { - std::string errorString = this->stream.str(); - char* result = new char[errorString.size() + 1]; - result[errorString.size()] = '\0'; - std::copy(errorString.begin(), errorString.end(), result); - return result; + errorString = this->stream.str(); + return errorString.c_str(); } } } diff --git a/src/storm/exceptions/BaseException.h b/src/storm/exceptions/BaseException.h index f9224cfb9..a3febc290 100644 --- a/src/storm/exceptions/BaseException.h +++ b/src/storm/exceptions/BaseException.h @@ -46,6 +46,10 @@ namespace storm { protected: // This stream stores the message of this exception. std::stringstream stream; + + private: + // storage for the string backing the C string returned by what() + mutable std::string errorString; }; } // namespace exceptions