diff --git a/src/tools/Exception.h b/src/tools/Exception.h index eddd046943f6b9bd3b1745690bcb37501c26f967..12f6fb50e178072474e051828cd0b8a5085c5e7e 100644 --- a/src/tools/Exception.h +++ b/src/tools/Exception.h @@ -256,6 +256,30 @@ public: } }; +/// Class representing a generic error +class ExceptionError : + public Exception { +public: + using Exception::Exception; + template<typename T> + ExceptionError& operator<<(const T & x) { + *((Exception*) this) <<x; + return *this; + } +}; + +/// Class representing a debug error (can only be thrown when using debug options) +class ExceptionDebug : + public Exception { +public: + using Exception::Exception; + template<typename T> + ExceptionDebug& operator<<(const T & x) { + *((Exception*) this) <<x; + return *this; + } +}; + #ifdef __GNUG__ // With GNU compiler, we can use __PRETTY_FUNCTION__ to get the function name #define __PLUMED_FUNCNAME __PRETTY_FUNCTION__ @@ -274,7 +298,7 @@ public: /// \relates PLMD::Exception /// Throw an exception with information about the position in the file. /// Messages can be inserted with `plumed_error()<<"message"`. -#define plumed_error() throw PLMD::Exception() << plumed_here +#define plumed_error() throw PLMD::ExceptionError() << plumed_here /// \relates PLMD::Exception /// Throw an exception with information about the position in the file @@ -305,11 +329,11 @@ public: /// \relates PLMD::Exception /// Same as \ref plumed_assert, but only evaluates the condition if NDEBUG is not defined. -#define plumed_dbg_assert(test) plumed_assert(test) +#define plumed_dbg_assert(test) if(!(test)) throw PLMD::ExceptionDebug() << plumed_here << PLMD::Exception::Assertion(#test) /// \relates PLMD::Exception /// Same as \ref plumed_massert, but only evaluates the condition if NDEBUG is not defined. -#define plumed_dbg_massert(test,msg) plumed_assert(test) << msg +#define plumed_dbg_massert(test,msg) plumed_dbg_assert(test) << msg #endif