exceptions.hh

Go to the documentation of this file.
00001 // $Id: exceptions.hh 5235 2008-07-03 15:03:49Z mnolte $
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 // the "format" the exception-type gets printed.  __FILE__ and
00110 // __LINE__ are standard C-defines, the GNU cpp-infofile claims that
00111 // C99 defines __func__ as well. __FUNCTION__ is a GNU-extension
00112 #ifdef DUNE_DEVEL_MODE
00113 # define THROWSPEC(E) #E << " [" << __func__ << ":" << __FILE__ << ":" << __LINE__ << "]: "
00114 #else
00115 # define THROWSPEC(E) #E << ": "
00116 #endif
00117 
00135 // this is the magic: use the usual do { ... } while (0) trick, create
00136 // the full message via a string stream and throw the created object
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 } // end namespace
00203 
00204 #endif

Generated on Sun Nov 15 22:28:12 2009 for dune-common by  doxygen 1.5.6