Browse Source
new exception
new exception
Created BaseException that can act as a stringstream. You can do the following: throw BaseException() << "some error " << variable << " foo"; Changed InvalidSettings to use BaseException, using this new syntax in Settings.tempestpy_adaptions
gereon
12 years ago
5 changed files with 55 additions and 38 deletions
-
40src/exceptions/BaseException.h
-
29src/exceptions/InvalidSettings.h
-
4src/mrmc.cpp
-
18src/utility/settings.cpp
-
2src/utility/settings.h
@ -0,0 +1,40 @@ |
|||
#ifndef BASEEXCEPTION_H_ |
|||
#define BASEEXCEPTION_H_ |
|||
|
|||
#include <exception> |
|||
#include <sstream> |
|||
|
|||
namespace mrmc { |
|||
namespace exceptions { |
|||
|
|||
class BaseException : public std::exception |
|||
{ |
|||
public: |
|||
BaseException() : exception() {} |
|||
BaseException(const BaseException& cp) |
|||
: exception(cp), stream(cp.stream.str()) |
|||
{ |
|||
} |
|||
|
|||
~BaseException() throw() { } |
|||
|
|||
template<class T> |
|||
BaseException& operator<<(const T& var) |
|||
{ |
|||
this->stream << var; |
|||
return *this; |
|||
} |
|||
|
|||
virtual const char* what() const throw() |
|||
{ |
|||
return this->stream.str().c_str(); |
|||
} |
|||
|
|||
private: |
|||
std::stringstream stream; |
|||
}; |
|||
|
|||
} // namespace exceptions |
|||
} // namespace mrmc |
|||
|
|||
#endif // BASEEXCEPTION_H_ |
@ -1,35 +1,16 @@ |
|||
#ifndef MRMC_EXCEPTIONS_INVALID_SETTINGS_H_ |
|||
#define MRMC_EXCEPTIONS_INVALID_SETTINGS_H_ |
|||
#ifndef INVALIDSETTINGS_H_ |
|||
#define INVALIDSETTINGS_H_ |
|||
|
|||
#include <exception> |
|||
#include "src/exceptions/BaseException.h" |
|||
|
|||
namespace mrmc { |
|||
namespace exceptions { |
|||
|
|||
//!This exception is thrown when a memory request can't be |
|||
//!fulfilled. |
|||
class InvalidSettings : public std::exception |
|||
class InvalidSettings : public BaseException |
|||
{ |
|||
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) |
|||
*/ |
|||
#ifdef _WIN32 |
|||
InvalidSettings() : exception("::mrmc::InvalidSettings"){} |
|||
InvalidSettings(const char * const s): exception(s) {} |
|||
#else |
|||
InvalidSettings() : exception() {} |
|||
InvalidSettings(const char * const s): exception() {} |
|||
|
|||
#endif |
|||
virtual const char* what() const throw() |
|||
{ return "mrmc::InvalidSettings"; } |
|||
}; |
|||
|
|||
} // namespace exceptions |
|||
} // namespace mrmc |
|||
|
|||
#endif // MRMC_EXCEPTIONS_INVALID_SETTINGS_H_ |
|||
#endif // INVALIDSETTINGS_H_ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue