Browse Source

Added missing contructors to all exceptions.

tempestpy_adaptions
PBerger 12 years ago
parent
commit
fe95c2225b
  1. 18
      src/exceptions/BaseException.h
  2. 22
      src/exceptions/FileIoException.h
  3. 30
      src/exceptions/InvalidArgumentException.h
  4. 10
      src/exceptions/InvalidSettingsException.h
  5. 33
      src/exceptions/InvalidStateException.h
  6. 53
      src/exceptions/NoConvergenceException.h
  7. 30
      src/exceptions/OutOfRangeException.h
  8. 26
      src/exceptions/WrongFileFormatException.h
  9. 4
      src/models/AtomicPropositionsLabeling.h

18
src/exceptions/BaseException.h

@ -17,6 +17,10 @@ class BaseException : public std::exception
{ {
} }
BaseException(const char* cstr) {
stream << cstr;
}
~BaseException() throw() { } ~BaseException() throw() { }
template<class T> template<class T>
@ -38,4 +42,18 @@ class BaseException : public std::exception
} // namespace exceptions } // namespace exceptions
} // namespace mrmc } // 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<exception_name> { \
public: \
exception_name() : BaseException() { \
} \
exception_name(const char* cstr) : BaseException(cstr) { \
} \
exception_name(const exception_name& cp) : BaseException(cp) { \
} \
};
#endif // MRMC_EXCEPTIONS_BASEEXCEPTION_H_ #endif // MRMC_EXCEPTIONS_BASEEXCEPTION_H_

22
src/exceptions/FileIoException.h

@ -8,22 +8,20 @@
#ifndef MRMC_EXCEPTIONS_FILEIOEXCEPTION_H_ #ifndef MRMC_EXCEPTIONS_FILEIOEXCEPTION_H_
#define MRMC_EXCEPTIONS_FILEIOEXCEPTION_H_ #define MRMC_EXCEPTIONS_FILEIOEXCEPTION_H_
#include "src/exceptions/BaseException.h"
namespace mrmc { namespace mrmc {
namespace exceptions { 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<FileIoException> {
public:
FileIoException() : BaseException() {
}
FileIoException(const char* cstr) : BaseException(cstr) {
}
FileIoException(const FileIoException& cp) : BaseException(cp) {
}
}; };
} }

30
src/exceptions/InvalidArgumentException.h

@ -1,31 +1,23 @@
#ifndef MRMC_EXCEPTIONS_INVALIDARGUMENTEXCEPTION_H_ #ifndef MRMC_EXCEPTIONS_INVALIDARGUMENTEXCEPTION_H_
#define MRMC_EXCEPTIONS_INVALIDARGUMENTEXCEPTION_H_ #define MRMC_EXCEPTIONS_INVALIDARGUMENTEXCEPTION_H_
#include <exception>
#include "src/exceptions/BaseException.h"
namespace mrmc { namespace mrmc {
namespace exceptions { 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<InvalidArgumentException> {
public:
InvalidArgumentException() {
}
InvalidArgumentException(const char* cstr) : BaseException(cstr) {
}
InvalidArgumentException(const InvalidArgumentException& cp) : BaseException(cp) {
}
}; };
} // namespace exceptions } // namespace exceptions

10
src/exceptions/InvalidSettingsException.h

@ -6,8 +6,14 @@
namespace mrmc { namespace mrmc {
namespace exceptions { namespace exceptions {
class InvalidSettingsException : public BaseException<InvalidSettingsException>
{
class InvalidSettingsException : public BaseException<InvalidSettingsException> {
public:
InvalidSettingsException() {
}
InvalidSettingsException(const char* cstr) : BaseException(cstr) {
}
InvalidSettingsException(const InvalidSettingsException& cp) : BaseException(cp) {
}
}; };
} // namespace exceptions } // namespace exceptions

33
src/exceptions/InvalidStateException.h

@ -1,33 +1,24 @@
#ifndef MRMC_EXCEPTIONS_INVALIDSTATEEXCEPTION_H_ #ifndef MRMC_EXCEPTIONS_INVALIDSTATEEXCEPTION_H_
#define MRMC_EXCEPTIONS_INVALIDSTATEEXCEPTION_H_ #define MRMC_EXCEPTIONS_INVALIDSTATEEXCEPTION_H_
#include <exception>
#include "src/exceptions/BaseException.h"
namespace mrmc { namespace mrmc {
namespace exceptions { 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<InvalidStateException> {
public:
InvalidStateException() {
}
InvalidStateException(const char* cstr) : BaseException(cstr) {
}
InvalidStateException(const InvalidStateException& cp) : BaseException(cp) {
}
}; };
} // namespace exceptions } // namespace exceptions

53
src/exceptions/NoConvergenceException.h

@ -1,53 +1,22 @@
#ifndef MRMC_EXCEPTIONS_NOCONVERGENCEEXCEPTION_H_ #ifndef MRMC_EXCEPTIONS_NOCONVERGENCEEXCEPTION_H_
#define MRMC_EXCEPTIONS_NOCONVERGENCEEXCEPTION_H_ #define MRMC_EXCEPTIONS_NOCONVERGENCEEXCEPTION_H_
#include <exception>
#include "src/exceptions/BaseException.h"
namespace mrmc { namespace mrmc {
namespace exceptions { 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<NoConvergenceException> {
public:
NoConvergenceException() {
}
NoConvergenceException(const char* cstr) : BaseException(cstr) {
}
NoConvergenceException(const NoConvergenceException& cp) : BaseException(cp) {
}
}; };
} // namespace exceptions } // namespace exceptions

30
src/exceptions/OutOfRangeException.h

@ -1,31 +1,23 @@
#ifndef MRMC_EXCEPTIONS_OUTOFRANGEEXCEPTION_H_ #ifndef MRMC_EXCEPTIONS_OUTOFRANGEEXCEPTION_H_
#define MRMC_EXCEPTIONS_OUTOFRANGEEXCEPTION_H_ #define MRMC_EXCEPTIONS_OUTOFRANGEEXCEPTION_H_
#include <exception>
#include "src/exceptions/BaseException.h"
namespace mrmc { namespace mrmc {
namespace exceptions { 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<OutOfRangeException> {
public:
OutOfRangeException() {
}
OutOfRangeException(const char* cstr) : BaseException(cstr) {
}
OutOfRangeException(const OutOfRangeException& cp) : BaseException(cp) {
}
}; };
} // namespace exceptions } // namespace exceptions

26
src/exceptions/WrongFileFormatException.h

@ -8,24 +8,24 @@
#ifndef MRMC_EXCEPTIONS_WRONGFILEFORMATEXCEPTION_H_ #ifndef MRMC_EXCEPTIONS_WRONGFILEFORMATEXCEPTION_H_
#define MRMC_EXCEPTIONS_WRONGFILEFORMATEXCEPTION_H_ #define MRMC_EXCEPTIONS_WRONGFILEFORMATEXCEPTION_H_
#include <exception>
#include "src/exceptions/BaseException.h"
namespace mrmc { namespace mrmc {
namespace exceptions { 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<WrongFileFormatException> {
public:
WrongFileFormatException() {
}
WrongFileFormatException(const char* cstr) : BaseException(cstr) {
}
WrongFileFormatException(const WrongFileFormatException& cp) : BaseException(cp) {
}
}; };
} //namespace exceptions } //namespace exceptions

4
src/models/AtomicPropositionsLabeling.h

@ -110,9 +110,7 @@ public:
*/ */
void addAtomicPropositionToState(std::string ap, const uint_fast64_t state) { void addAtomicPropositionToState(std::string ap, const uint_fast64_t state) {
if (nameToLabelingMap.count(ap) == 0) { 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) { if (state >= stateCount) {
throw mrmc::exceptions::OutOfRangeException("State index out of range."); throw mrmc::exceptions::OutOfRangeException("State index out of range.");

Loading…
Cancel
Save