exceptions.hh

Go to the documentation of this file.
00001 // $Id: exceptions.hh 4768 2006-11-04 12:25:51Z mblatt $
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 // the "format" the exception-type gets printed.  __FILE__ and
00104 // __LINE__ are standard C-defines, the GNU cpp-infofile claims that
00105 // C99 defines __func__ as well. __FUNCTION__ is a GNU-extension
00106 #ifdef DUNE_DEVEL_MODE
00107 # define THROWSPEC(E) #E << " [" << __func__ << ":" << __FILE__ << ":" << __LINE__ << "]: "
00108 #else
00109 # define THROWSPEC(E) #E << ": "
00110 #endif
00111 
00129 // this is the magic: use the usual do { ... } while (0) trick, create
00130 // the full message via a string stream and throw the created object
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 } // end namespace
00197 
00198 #endif

Generated on 9 Apr 2008 with Doxygen (ver 1.5.2) [logfile].