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