00001
00002
00003 #ifndef DUNE_EXCEPTIONS_HH
00004 #define DUNE_EXCEPTIONS_HH
00005
00006 #include <string>
00007 #include <sstream>
00008
00009 namespace Dune {
00010
00011
00086 class Exception {
00087 public:
00088 void message(std::string message);
00089
00090 std::string what() { return _message; };
00091 private:
00092 std::string _message;
00093 };
00094
00095 inline void Exception::message(std::string message) {
00096 _message = message;
00097 }
00098
00099 inline std::ostream& operator<<(std::ostream &stream, Exception &e) {
00100 return stream << e.what();
00101 }
00102
00103
00104
00105
00106 #ifdef DUNE_DEVEL_MODE
00107 # define THROWSPEC(E) #E << " [" << __func__ << ":" << __FILE__ << ":" << __LINE__ << "]: "
00108 #else
00109 # define THROWSPEC(E) #E << ": "
00110 #endif
00111
00129
00130
00131 #define DUNE_THROW(E, m) do { E th__ex; std::ostringstream th__out; \
00132 th__out << THROWSPEC(E) << m; th__ex.message(th__out.str()); throw th__ex; \
00133 } while (0)
00134
00144 class IOError : public Exception {};
00145
00154 class MathError : public Exception {};
00155
00167 class RangeError : public Exception {};
00168
00176 class NotImplemented : public Exception {};
00177
00184 class SystemError : public Exception {};
00185
00189 class OutOfMemoryError : public SystemError {};
00190
00194 class InvalidStateException : public Exception {};
00195
00196 }
00197
00198 #endif