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