COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/hugo/error.h @ 540:405ccc3105e1

Last change on this file since 540:405ccc3105e1 was 539:fb261e3a9a0f, checked in by Akos Ladanyi, 21 years ago

Rename 'include' to 'hugo' (for automake)

File size: 1.6 KB
Line 
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
15namespace 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
Note: See TracBrowser for help on using the repository browser.