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() {
// 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 "";
}
}
}

12
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;

3
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<typename T> \
exception_name& operator<<(T const& var) { \
this->stream << var; \

Loading…
Cancel
Save