exceptions.hh
Go to the documentation of this file.00001
00002
00003
00004
00005 #ifndef DUNE_EXCEPTIONS_HH
00006 #define DUNE_EXCEPTIONS_HH
00007
00008 #include <string>
00009 #include <sstream>
00010
00011 namespace Dune {
00012
00013
00088 class Exception {
00089 public:
00090 void message(const std::string &message);
00091 const std::string& what() const;
00092 private:
00093 std::string _message;
00094 };
00095
00096 inline void Exception::message(const std::string &message)
00097 {
00098 _message = message;
00099 }
00100
00101 inline const std::string& Exception::what() const
00102 {
00103 return _message;
00104 }
00105
00106 inline std::ostream& operator<<(std::ostream &stream, const Exception &e)
00107 {
00108 return stream << e.what();
00109 }
00110
00111
00112
00113
00114 #ifdef DUNE_DEVEL_MODE
00115 # define THROWSPEC(E) #E << " [" << __func__ << ":" << __FILE__ << ":" << __LINE__ << "]: "
00116 #else
00117 # define THROWSPEC(E) #E << ": "
00118 #endif
00119
00141
00142
00143 #define DUNE_THROW(E, m) do { E th__ex; std::ostringstream th__out; \
00144 th__out << THROWSPEC(E) << m; th__ex.message(th__out.str()); throw th__ex; \
00145 } while (0)
00146
00156 class IOError : public Exception {};
00157
00166 class MathError : public Exception {};
00167
00179 class RangeError : public Exception {};
00180
00188 class NotImplemented : public Exception {};
00189
00196 class SystemError : public Exception {};
00197
00201 class OutOfMemoryError : public SystemError {};
00202
00206 class InvalidStateException : public Exception {};
00207
00208 }
00209
00210 #endif