src/include/error.h
changeset 489 afbdf8a3a633
child 490 ceb56ff9d07f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/include/error.h	Thu Apr 29 22:39:17 2004 +0000
     1.3 @@ -0,0 +1,64 @@
     1.4 +// -*- C++ -*- //
     1.5 +
     1.6 +#ifndef HUGO_ERROR_H
     1.7 +#define HUGO_ERROR_H
     1.8 +
     1.9 +//! \file
    1.10 +//! \brief Basic error handling (signaling) routines.
    1.11 +
    1.12 +#include <string>
    1.13 +#include <sstream>
    1.14 +
    1.15 +
    1.16 +namespace hugo {
    1.17 +
    1.18 +  /**
    1.19 +   * \brief Generic exception class.
    1.20 +   *
    1.21 +   * \todo Do we need this?
    1.22 +   *
    1.23 +   * \todo Don't we need different kind of exceptions for different kind
    1.24 +   * of errors?
    1.25 +   * Shouldn't we use <stdexcept> instead?
    1.26 +   */
    1.27 +  class Exception : public std::exception {
    1.28 +  protected:
    1.29 +    std::ostringstream buf;
    1.30 +  public:
    1.31 +    Exception() {}
    1.32 +    explicit Exception(const std::string &s) { buf << s; }
    1.33 +    Exception(const Exception &e) { buf << e.buf.str(); }
    1.34 +    virtual ~Exception() throw() {}
    1.35 +    
    1.36 +    virtual const char* what() const throw() {
    1.37 +      return buf.str().c_str();
    1.38 +    }
    1.39 +
    1.40 +    Exception& operator<<(std::string const& s) { buf << s; return *this; }
    1.41 +    Exception& operator<<(char const *s) { buf << s; return *this; }
    1.42 +    Exception& operator<<(int i) { buf << i; return *this; }
    1.43 +  };
    1.44 +
    1.45 +  /**
    1.46 +   * \brief Generic error signaling function.
    1.47 +   *
    1.48 +   * \todo Do we really need this? Is it helpful?
    1.49 +   */
    1.50 +  inline void fault(const std::string &msg) {
    1.51 +    throw Exception(msg);
    1.52 +  }
    1.53 +
    1.54 +  /**
    1.55 +   * \brief Macro for mark not yet implemented features.
    1.56 +   *
    1.57 +   * \todo Is this the right place for this? It should be used only in
    1.58 +   * modules under development.
    1.59 +   */
    1.60 +
    1.61 +# define FIXME(msg) \
    1.62 +    do { throw ::hugo::Exception("FIXME: " msg) << " (in: "    \
    1.63 +      << __FILE__ << ", " << __LINE__ << ")";                  \
    1.64 +    } while(false)
    1.65 +
    1.66 +}
    1.67 +#endif // HUGO_ERROR_H