Browse Source

Output exception type in exception message

tempestpy_adaptions
Matthias Volk 6 years ago
parent
commit
87cd72f237
  1. 19
      src/storm/exceptions/BaseException.cpp
  2. 12
      src/storm/exceptions/BaseException.h
  3. 3
      src/storm/exceptions/ExceptionMacros.h

19
src/storm/exceptions/BaseException.cpp

@ -5,11 +5,11 @@ namespace storm {
BaseException::BaseException() : exception() { BaseException::BaseException() : exception() {
// Intentionally left empty. // Intentionally left empty.
} }
BaseException::BaseException(BaseException const& other) : exception(other), stream(other.stream.str()) { BaseException::BaseException(BaseException const& other) : exception(other), stream(other.stream.str()) {
// Intentionally left empty. // Intentionally left empty.
} }
BaseException::BaseException(char const* cstr) { BaseException::BaseException(char const* cstr) {
stream << cstr; stream << cstr;
} }
@ -17,10 +17,21 @@ namespace storm {
BaseException::~BaseException() { BaseException::~BaseException() {
// Intentionally left empty. // Intentionally left empty.
} }
const char* BaseException::what() const NOEXCEPT { 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(); return errorString.c_str();
} }
std::string BaseException::type() const {
return "BaseException";
}
std::string BaseException::additionalInfo() const {
return "";
}
} }
} }

12
src/storm/exceptions/BaseException.h

@ -42,7 +42,17 @@ namespace storm {
* @return The message associated with this exception. * @return The message associated with this exception.
*/ */
virtual const char* what() const NOEXCEPT override; 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: protected:
// This stream stores the message of this exception. // This stream stores the message of this exception.
std::stringstream stream; std::stringstream stream;

3
src/storm/exceptions/ExceptionMacros.h

@ -16,6 +16,9 @@ exception_name(exception_name const& cp) : BaseException(cp) { \
} \ } \
~exception_name() throw() { \ ~exception_name() throw() { \
} \ } \
virtual std::string type() const override { \
return #exception_name; \
} \
template<typename T> \ template<typename T> \
exception_name& operator<<(T const& var) { \ exception_name& operator<<(T const& var) { \
this->stream << var; \ this->stream << var; \

Loading…
Cancel
Save