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