From 87cd72f237af56d14fd869927f5eb60cbdd2daab Mon Sep 17 00:00:00 2001 From: Matthias Volk Date: Thu, 14 Feb 2019 16:48:24 +0100 Subject: [PATCH] Output exception type in exception message --- src/storm/exceptions/BaseException.cpp | 19 +++++++++++++++---- src/storm/exceptions/BaseException.h | 12 +++++++++++- src/storm/exceptions/ExceptionMacros.h | 3 +++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/storm/exceptions/BaseException.cpp b/src/storm/exceptions/BaseException.cpp index 86119f600..592e4d511 100644 --- a/src/storm/exceptions/BaseException.cpp +++ b/src/storm/exceptions/BaseException.cpp @@ -5,11 +5,11 @@ namespace storm { BaseException::BaseException() : exception() { // Intentionally left empty. } - + BaseException::BaseException(BaseException const& other) : exception(other), stream(other.stream.str()) { // Intentionally left empty. } - + BaseException::BaseException(char const* cstr) { stream << cstr; } @@ -17,10 +17,21 @@ namespace storm { BaseException::~BaseException() { // Intentionally left empty. } - + const char* BaseException::what() const NOEXCEPT { - errorString = this->stream.str(); + errorString = this->type() + ": " + this->stream.str(); + if (!this->additionalInfo().empty()) { + errorString += " " + this->additionalInfo(); + } return errorString.c_str(); } + + std::string BaseException::type() const { + return "BaseException"; + } + + std::string BaseException::additionalInfo() const { + return ""; + } } } diff --git a/src/storm/exceptions/BaseException.h b/src/storm/exceptions/BaseException.h index a3febc290..2b4126500 100644 --- a/src/storm/exceptions/BaseException.h +++ b/src/storm/exceptions/BaseException.h @@ -42,7 +42,17 @@ namespace storm { * @return The message associated with this exception. */ virtual const char* what() const NOEXCEPT override; - + + /*! + * Returns the type of the exception. + */ + virtual std::string type() const; + + /*! + * Returns additional information about the exception. + */ + virtual std::string additionalInfo() const; + protected: // This stream stores the message of this exception. std::stringstream stream; diff --git a/src/storm/exceptions/ExceptionMacros.h b/src/storm/exceptions/ExceptionMacros.h index 5d1090a06..556ad1992 100644 --- a/src/storm/exceptions/ExceptionMacros.h +++ b/src/storm/exceptions/ExceptionMacros.h @@ -16,6 +16,9 @@ exception_name(exception_name const& cp) : BaseException(cp) { \ } \ ~exception_name() throw() { \ } \ +virtual std::string type() const override { \ + return #exception_name; \ +} \ template \ exception_name& operator<<(T const& var) { \ this->stream << var; \