#ifndef EXCEPTION_HH_INCLUDED #define EXCEPTION_HH_INCLUDED #include #include #include #include /** * General exception */ class Exception : public std::exception { public: /** * Constructor. * * \param error error message */ Exception(const std::string& error) : std::exception(), buffer(error) {} /** * Destructor. */ ~Exception() throw() {} /** * Get error message. * * \return error message */ virtual const char* what() const throw() { return buffer.c_str(); } /** * Print error message of JException. * * \param out output stream * \param exception exception */ friend inline std::ostream& operator<<(std::ostream& out, const Exception& exception) { return out << exception.what(); } /** * Get output stream for conversion of exception. * * Note that the ostream is emptied before use. * * \return ostream */ static inline std::ostream& getOstream() { static std::ostringstream buffer; buffer.str(""); return buffer; } private: const std::string buffer; }; /** * Marco for throwing exception with std::ostream compatible message. * * \param Exception_t exception * \param A message */ #ifndef THROW #define THROW(Exception_t, A) do { throw Exception_t(static_cast(Exception::getOstream() << __FILE__ << ':' << __LINE__ << std::endl << A).str()); } while(0) #endif #endif