alpar@883: // -*- C++ -*- // alpar@883: alpar@883: #ifndef HUGO_ERROR_H alpar@883: #define HUGO_ERROR_H alpar@883: alpar@883: //! \ingroup misc alpar@883: //! \file alpar@883: //! \brief Basic error handling (signaling) routines. alpar@883: alpar@883: #include alpar@883: #include alpar@883: #include alpar@883: alpar@883: alpar@883: namespace hugo { alpar@883: alpar@883: /** alpar@883: * \brief Generic exception class. alpar@883: * alpar@883: * \todo Do we need this? alpar@883: * alpar@883: * \todo Don't we need different kind of exceptions for different kind alpar@883: * of errors? alpar@883: * Shouldn't we use \ instead? alpar@883: */ alpar@883: class Exception : public std::exception { alpar@883: protected: alpar@883: std::ostringstream buf; alpar@883: public: alpar@883: Exception() {} alpar@883: explicit Exception(const std::string &s) { buf << s; } alpar@883: Exception(const Exception &e) : std::exception() { alpar@883: buf << e.buf.str(); alpar@883: } alpar@883: virtual ~Exception() throw() {} alpar@883: alpar@883: virtual const char* what() const throw() { alpar@883: return buf.str().c_str(); alpar@883: } alpar@883: alpar@883: Exception& operator<<(std::string const& s) { buf << s; return *this; } alpar@883: Exception& operator<<(char const *s) { buf << s; return *this; } alpar@883: Exception& operator<<(int i) { buf << i; return *this; } alpar@883: }; alpar@883: alpar@883: /** alpar@883: * \brief Generic error signaling function. alpar@883: * alpar@883: * \todo Do we really need this? Is it helpful? alpar@883: */ alpar@883: inline void fault(const std::string &msg) { alpar@883: throw Exception(msg); alpar@883: } alpar@883: alpar@883: /** alpar@883: * \brief Macro for mark not yet implemented features. alpar@883: * alpar@883: * \todo Is this the right place for this? It should be used only in alpar@883: * modules under development. alpar@883: */ alpar@883: alpar@883: # define FIXME(msg) \ alpar@883: do { throw ::hugo::Exception() << "FIXME: " msg " (in: " \ alpar@883: __FILE__ ", " << __LINE__ << ")"; \ alpar@883: } while(false) alpar@883: alpar@883: } alpar@883: #endif // HUGO_ERROR_H