src/hugo/error.h
author alpar
Thu, 16 Sep 2004 19:24:15 +0000
changeset 874 2195bc090dfe
parent 508 95f8f7171bae
permissions -rw-r--r--
Document the file itself.
     1 // -*- C++ -*- //
     2 
     3 #ifndef HUGO_ERROR_H
     4 #define HUGO_ERROR_H
     5 
     6 //! \ingroup misc
     7 //! \file
     8 //! \brief Basic error handling (signaling) routines.
     9 
    10 #include <exception>
    11 #include <string>
    12 #include <sstream>
    13 
    14 
    15 namespace hugo {
    16 
    17   /**
    18    * \brief Generic exception class.
    19    *
    20    * \todo Do we need this?
    21    *
    22    * \todo Don't we need different kind of exceptions for different kind
    23    * of errors?
    24    * Shouldn't we use \<stdexcept\> instead?
    25    */
    26   class Exception : public std::exception {
    27   protected:
    28     std::ostringstream buf;
    29   public:
    30     Exception() {}
    31     explicit Exception(const std::string &s) { buf << s; }
    32     Exception(const Exception &e) : std::exception() {
    33       buf << e.buf.str();
    34     }
    35     virtual ~Exception() throw() {}
    36     
    37     virtual const char* what() const throw() {
    38       return buf.str().c_str();
    39     }
    40 
    41     Exception& operator<<(std::string const& s) { buf << s; return *this; }
    42     Exception& operator<<(char const *s) { buf << s; return *this; }
    43     Exception& operator<<(int i) { buf << i; return *this; }
    44   };
    45 
    46   /**
    47    * \brief Generic error signaling function.
    48    *
    49    * \todo Do we really need this? Is it helpful?
    50    */
    51   inline void fault(const std::string &msg) {
    52     throw Exception(msg);
    53   }
    54 
    55   /**
    56    * \brief Macro for mark not yet implemented features.
    57    *
    58    * \todo Is this the right place for this? It should be used only in
    59    * modules under development.
    60    */
    61 
    62 # define FIXME(msg) \
    63     do { throw ::hugo::Exception() << "FIXME: " msg " (in: "    \
    64       __FILE__ ", " << __LINE__ << ")";                         \
    65     } while(false)
    66 
    67 }
    68 #endif // HUGO_ERROR_H