From fe95c2225b801518317a2580c8bff2a0e256a931 Mon Sep 17 00:00:00 2001 From: PBerger Date: Mon, 17 Dec 2012 04:01:21 +0100 Subject: [PATCH] Added missing contructors to all exceptions. --- src/exceptions/BaseException.h | 18 ++++++++ src/exceptions/FileIoException.h | 22 +++++----- src/exceptions/InvalidArgumentException.h | 30 +++++-------- src/exceptions/InvalidSettingsException.h | 10 ++++- src/exceptions/InvalidStateException.h | 33 +++++--------- src/exceptions/NoConvergenceException.h | 53 +++++------------------ src/exceptions/OutOfRangeException.h | 30 +++++-------- src/exceptions/WrongFileFormatException.h | 26 +++++------ src/models/AtomicPropositionsLabeling.h | 4 +- 9 files changed, 95 insertions(+), 131 deletions(-) diff --git a/src/exceptions/BaseException.h b/src/exceptions/BaseException.h index fcf92ee2c..d8767e8d9 100644 --- a/src/exceptions/BaseException.h +++ b/src/exceptions/BaseException.h @@ -16,6 +16,10 @@ class BaseException : public std::exception : exception(cp), stream(cp.stream.str()) { } + + BaseException(const char* cstr) { + stream << cstr; + } ~BaseException() throw() { } @@ -38,4 +42,18 @@ class BaseException : public std::exception } // namespace exceptions } // namespace mrmc +/* Macro to generate descendant exception classes. + * As all classes are nearly the same, this makes changing common features much easier. + */ +#define MRMC_EXCEPTION_DEFINE_NEW(exception_name) class exception_name : public BaseException { \ +public: \ + exception_name() : BaseException() { \ + } \ + exception_name(const char* cstr) : BaseException(cstr) { \ + } \ + exception_name(const exception_name& cp) : BaseException(cp) { \ + } \ +}; + + #endif // MRMC_EXCEPTIONS_BASEEXCEPTION_H_ diff --git a/src/exceptions/FileIoException.h b/src/exceptions/FileIoException.h index 5fd72dad9..6ae8a9fb8 100644 --- a/src/exceptions/FileIoException.h +++ b/src/exceptions/FileIoException.h @@ -8,22 +8,20 @@ #ifndef MRMC_EXCEPTIONS_FILEIOEXCEPTION_H_ #define MRMC_EXCEPTIONS_FILEIOEXCEPTION_H_ +#include "src/exceptions/BaseException.h" + namespace mrmc { namespace exceptions { -class FileIoException : public std::exception { - public: -#ifdef _WIN32 - FileIoException() : exception("::mrmc::FileIoException"){}; - FileIoException(const char * const s): exception(s) {}; -#else - FileIoException() {}; - FileIoException(const char * const s): exception() {}; -#endif - virtual const char* what() const throw(){ - { return "mrmc::FileIoException"; } - } +class FileIoException : public BaseException { +public: + FileIoException() : BaseException() { + } + FileIoException(const char* cstr) : BaseException(cstr) { + } + FileIoException(const FileIoException& cp) : BaseException(cp) { + } }; } diff --git a/src/exceptions/InvalidArgumentException.h b/src/exceptions/InvalidArgumentException.h index 051e4c000..c25c31fd9 100644 --- a/src/exceptions/InvalidArgumentException.h +++ b/src/exceptions/InvalidArgumentException.h @@ -1,31 +1,23 @@ #ifndef MRMC_EXCEPTIONS_INVALIDARGUMENTEXCEPTION_H_ #define MRMC_EXCEPTIONS_INVALIDARGUMENTEXCEPTION_H_ -#include +#include "src/exceptions/BaseException.h" namespace mrmc { namespace exceptions { -//!This exception is thrown when a parameter is invalid in this context -class InvalidArgumentException : public std::exception -{ - public: -/* The Visual C++-Version of the exception class has constructors accepting - * a char*-constant; The GCC version does not have these - * - * As the "extended" constructor is used in the sparse matrix code, a dummy - * constructor is used under linux (which will ignore the parameter) +/*! + * @brief This exception is thrown when a parameter is invalid in this context */ -#ifdef _WIN32 - InvalidArgumentException() : exception("::mrmc::InvalidArgumentException"){} - InvalidArgumentException(const char * const s): exception(s) {} -#else - InvalidArgumentException() : exception() {} - InvalidArgumentException(const char * const s): exception() {} -#endif - virtual const char* what() const throw() - { return "mrmc::InvalidArgumentException"; } +class InvalidArgumentException : public BaseException { +public: + InvalidArgumentException() { + } + InvalidArgumentException(const char* cstr) : BaseException(cstr) { + } + InvalidArgumentException(const InvalidArgumentException& cp) : BaseException(cp) { + } }; } // namespace exceptions diff --git a/src/exceptions/InvalidSettingsException.h b/src/exceptions/InvalidSettingsException.h index 315ec64e7..cd51fa549 100644 --- a/src/exceptions/InvalidSettingsException.h +++ b/src/exceptions/InvalidSettingsException.h @@ -6,8 +6,14 @@ namespace mrmc { namespace exceptions { -class InvalidSettingsException : public BaseException -{ +class InvalidSettingsException : public BaseException { +public: + InvalidSettingsException() { + } + InvalidSettingsException(const char* cstr) : BaseException(cstr) { + } + InvalidSettingsException(const InvalidSettingsException& cp) : BaseException(cp) { + } }; } // namespace exceptions diff --git a/src/exceptions/InvalidStateException.h b/src/exceptions/InvalidStateException.h index 32b07a659..7959e71dc 100644 --- a/src/exceptions/InvalidStateException.h +++ b/src/exceptions/InvalidStateException.h @@ -1,33 +1,24 @@ #ifndef MRMC_EXCEPTIONS_INVALIDSTATEEXCEPTION_H_ #define MRMC_EXCEPTIONS_INVALIDSTATEEXCEPTION_H_ -#include +#include "src/exceptions/BaseException.h" namespace mrmc { namespace exceptions { -//!This exception is thrown when a memory request can't be -//!fulfilled. -class InvalidStateException : public std::exception -{ - public: -/* The Visual C++-Version of the exception class has constructors accepting - * a char*-constant; The GCC version does not have these - * - * As the "extended" constructor is used in the sparse matrix code, a dummy - * constructor is used under linux (which will ignore the parameter) +/*! + * @brief This exception is thrown when a memory request can't be + * fulfilled. */ -#ifdef _WIN32 - InvalidStateException() : exception("::mrmc::InvalidStateException"){} - InvalidStateException(const char * const s): exception(s) {} -#else - InvalidStateException() : exception() {} - InvalidStateException(const char * const s): exception() {} - -#endif - virtual const char* what() const throw() - { return "mrmc::InvalidStateException"; } +class InvalidStateException : public BaseException { +public: + InvalidStateException() { + } + InvalidStateException(const char* cstr) : BaseException(cstr) { + } + InvalidStateException(const InvalidStateException& cp) : BaseException(cp) { + } }; } // namespace exceptions diff --git a/src/exceptions/NoConvergenceException.h b/src/exceptions/NoConvergenceException.h index 1ea6bd655..c67fa54fa 100644 --- a/src/exceptions/NoConvergenceException.h +++ b/src/exceptions/NoConvergenceException.h @@ -1,53 +1,22 @@ #ifndef MRMC_EXCEPTIONS_NOCONVERGENCEEXCEPTION_H_ #define MRMC_EXCEPTIONS_NOCONVERGENCEEXCEPTION_H_ -#include +#include "src/exceptions/BaseException.h" namespace mrmc { namespace exceptions { -//!This exception is thrown when an iterative solver failed to converge with the given maxIterations -class NoConvergenceException : public std::exception -{ - public: -/* The Visual C++-Version of the exception class has constructors accepting - * a char*-constant; The GCC version does not have these - * - * As the "extended" constructor is used in the sparse matrix code, a dummy - * constructor is used under linux (which will ignore the parameter) +/*! + * @brief This exception is thrown when an iterative solver failed to converge with the given maxIterations */ -#ifdef _WIN32 - NoConvergenceException() : exception("::mrmc::exceptions::NoConvergenceException"){ - iterations = -1; - maxIterations = -1; - } - NoConvergenceException(const char * const s, int iterations, int maxIterations): exception(s) { - this->iterations = iterations; - this->maxIterations = maxIterations; - } -#else - NoConvergenceException() : exception() { - iterations = -1; - maxIterations = -1; - } - NoConvergenceException(const char * const s, int iterations, int maxIterations): exception() { - this->iterations = iterations; - this->maxIterations = maxIterations; - } - -#endif - virtual const char* what() const throw() - { return "mrmc::exceptions::NoConvergenceException"; } - - int getIterationCount() const { - return iterations; - } - int getMaxIterationCount() const { - return maxIterations; - } - private: - int iterations; - int maxIterations; +class NoConvergenceException : public BaseException { +public: + NoConvergenceException() { + } + NoConvergenceException(const char* cstr) : BaseException(cstr) { + } + NoConvergenceException(const NoConvergenceException& cp) : BaseException(cp) { + } }; } // namespace exceptions diff --git a/src/exceptions/OutOfRangeException.h b/src/exceptions/OutOfRangeException.h index dffcd4e78..f5b2660b9 100644 --- a/src/exceptions/OutOfRangeException.h +++ b/src/exceptions/OutOfRangeException.h @@ -1,31 +1,23 @@ #ifndef MRMC_EXCEPTIONS_OUTOFRANGEEXCEPTION_H_ #define MRMC_EXCEPTIONS_OUTOFRANGEEXCEPTION_H_ -#include +#include "src/exceptions/BaseException.h" namespace mrmc { namespace exceptions { -//!This exception is thrown when a parameter is not in the range of valid values -class OutOfRangeException : public std::exception -{ - public: -/* The Visual C++-Version of the exception class has constructors accepting - * a char*-constant; The GCC version does not have these - * - * As the "extended" constructor is used in the sparse matrix code, a dummy - * constructor is used under linux (which will ignore the parameter) +/* + * @briefThis exception is thrown when a parameter is not in the range of valid values */ -#ifdef _WIN32 - OutOfRangeException() : exception("::mrmc::OutOfRangeException"){} - OutOfRangeException(const char * const s): exception(s) {} -#else - OutOfRangeException() : exception() {} - OutOfRangeException(const char * const s): exception() {} -#endif - virtual const char* what() const throw() - { return "mrmc::OutOfRangeException"; } +class OutOfRangeException : public BaseException { +public: + OutOfRangeException() { + } + OutOfRangeException(const char* cstr) : BaseException(cstr) { + } + OutOfRangeException(const OutOfRangeException& cp) : BaseException(cp) { + } }; } // namespace exceptions diff --git a/src/exceptions/WrongFileFormatException.h b/src/exceptions/WrongFileFormatException.h index 13cb53b2d..490623440 100644 --- a/src/exceptions/WrongFileFormatException.h +++ b/src/exceptions/WrongFileFormatException.h @@ -8,24 +8,24 @@ #ifndef MRMC_EXCEPTIONS_WRONGFILEFORMATEXCEPTION_H_ #define MRMC_EXCEPTIONS_WRONGFILEFORMATEXCEPTION_H_ -#include +#include "src/exceptions/BaseException.h" namespace mrmc { namespace exceptions { -class WrongFileFormatException : public std::exception { - public: -#ifdef _WIN32 - WrongFileFormatException() : exception("::mrmc::WrongFileFormatException"){}; - WrongFileFormatException(const char * const s): exception(s) {}; -#else - WrongFileFormatException() {}; - WrongFileFormatException(const char * const s): exception() {}; -#endif - virtual const char* what() const throw(){ - { return "mrmc::WrongFileFormatException"; } - } +/*! + * @brief This exception is thrown when an input file + * contains invalid or missing keys. + */ +class WrongFileFormatException : public BaseException { +public: + WrongFileFormatException() { + } + WrongFileFormatException(const char* cstr) : BaseException(cstr) { + } + WrongFileFormatException(const WrongFileFormatException& cp) : BaseException(cp) { + } }; } //namespace exceptions diff --git a/src/models/AtomicPropositionsLabeling.h b/src/models/AtomicPropositionsLabeling.h index d7632445f..f4d52b783 100644 --- a/src/models/AtomicPropositionsLabeling.h +++ b/src/models/AtomicPropositionsLabeling.h @@ -110,9 +110,7 @@ public: */ void addAtomicPropositionToState(std::string ap, const uint_fast64_t state) { if (nameToLabelingMap.count(ap) == 0) { - /*throw mrmc::exceptions::OutOfRangeException("Atomic Proposition '" << ap << "' unknown.");*/ - // TODO !!! - throw mrmc::exceptions::OutOfRangeException("Atomic Proposition '' unknown."); + throw mrmc::exceptions::OutOfRangeException() << "Atomic Proposition '" << ap << "' unknown."; } if (state >= stateCount) { throw mrmc::exceptions::OutOfRangeException("State index out of range.");