Last change
on this file since 490:ceb56ff9d07f was
490:ceb56ff9d07f,
checked in by Mihaly Barasz, 20 years ago
|
The -W gcc option _does_ matter even if you use -Wall!
Minor changes.
|
File size:
1.6 KB
|
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 | |
---|
[490] | 9 | #include <exception> |
---|
[489] | 10 | #include <string> |
---|
| 11 | #include <sstream> |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | namespace hugo { |
---|
| 15 | |
---|
| 16 | /** |
---|
| 17 | * \brief Generic exception class. |
---|
| 18 | * |
---|
| 19 | * \todo Do we need this? |
---|
| 20 | * |
---|
| 21 | * \todo Don't we need different kind of exceptions for different kind |
---|
| 22 | * of errors? |
---|
| 23 | * Shouldn't we use <stdexcept> instead? |
---|
| 24 | */ |
---|
| 25 | class Exception : public std::exception { |
---|
| 26 | protected: |
---|
| 27 | std::ostringstream buf; |
---|
| 28 | public: |
---|
| 29 | Exception() {} |
---|
| 30 | explicit Exception(const std::string &s) { buf << s; } |
---|
[490] | 31 | Exception(const Exception &e) : std::exception() { |
---|
| 32 | buf << e.buf.str(); |
---|
| 33 | } |
---|
[489] | 34 | virtual ~Exception() throw() {} |
---|
| 35 | |
---|
| 36 | virtual const char* what() const throw() { |
---|
| 37 | return buf.str().c_str(); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | Exception& operator<<(std::string const& s) { buf << s; return *this; } |
---|
| 41 | Exception& operator<<(char const *s) { buf << s; return *this; } |
---|
| 42 | Exception& operator<<(int i) { buf << i; return *this; } |
---|
| 43 | }; |
---|
| 44 | |
---|
| 45 | /** |
---|
| 46 | * \brief Generic error signaling function. |
---|
| 47 | * |
---|
| 48 | * \todo Do we really need this? Is it helpful? |
---|
| 49 | */ |
---|
| 50 | inline void fault(const std::string &msg) { |
---|
| 51 | throw Exception(msg); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | /** |
---|
| 55 | * \brief Macro for mark not yet implemented features. |
---|
| 56 | * |
---|
| 57 | * \todo Is this the right place for this? It should be used only in |
---|
| 58 | * modules under development. |
---|
| 59 | */ |
---|
| 60 | |
---|
| 61 | # define FIXME(msg) \ |
---|
[490] | 62 | do { throw ::hugo::Exception() << "FIXME: " msg " (in: " \ |
---|
| 63 | __FILE__ ", " << __LINE__ << ")"; \ |
---|
[489] | 64 | } while(false) |
---|
| 65 | |
---|
| 66 | } |
---|
| 67 | #endif // HUGO_ERROR_H |
---|
Note: See
TracBrowser
for help on using the repository browser.