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