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