exceptions.hh
Go to the documentation of this file.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(const std::string &message);
00089 const std::string& what() const;
00090 private:
00091 std::string _message;
00092 };
00093
00094 inline void Exception::message(const std::string &message)
00095 {
00096 _message = message;
00097 }
00098
00099 inline const std::string& Exception::what() const
00100 {
00101 return _message;
00102 }
00103
00104 inline std::ostream& operator<<(std::ostream &stream, const Exception &e)
00105 {
00106 return stream << e.what();
00107 }
00108
00109
00110
00111
00112 #ifdef DUNE_DEVEL_MODE
00113 # define THROWSPEC(E) #E << " [" << __func__ << ":" << __FILE__ << ":" << __LINE__ << "]: "
00114 #else
00115 # define THROWSPEC(E) #E << ": "
00116 #endif
00117
00135
00136
00137 #define DUNE_THROW(E, m) do { E th__ex; std::ostringstream th__out; \
00138 th__out << THROWSPEC(E) << m; th__ex.message(th__out.str()); throw th__ex; \
00139 } while (0)
00140
00150 class IOError : public Exception {};
00151
00160 class MathError : public Exception {};
00161
00173 class RangeError : public Exception {};
00174
00182 class NotImplemented : public Exception {};
00183
00190 class SystemError : public Exception {};
00191
00195 class OutOfMemoryError : public SystemError {};
00196
00200 class InvalidStateException : public Exception {};
00201
00202 }
00203
00204 #endif