exceptions.hh

Go to the documentation of this file.
00001 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002 // vi: set et ts=8 sw=2 sts=2:
00003 // $Id: exceptions.hh 5867 2010-01-26 10:17:36Z mdroh_01 $
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 // the "format" the exception-type gets printed.  __FILE__ and
00112 // __LINE__ are standard C-defines, the GNU cpp-infofile claims that
00113 // C99 defines __func__ as well. __FUNCTION__ is a GNU-extension
00114 #ifdef DUNE_DEVEL_MODE
00115 # define THROWSPEC(E) #E << " [" << __func__ << ":" << __FILE__ << ":" << __LINE__ << "]: "
00116 #else
00117 # define THROWSPEC(E) #E << ": "
00118 #endif
00119 
00141 // this is the magic: use the usual do { ... } while (0) trick, create
00142 // the full message via a string stream and throw the created object
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 } // end namespace
00209 
00210 #endif
Generated on Mon Apr 26 10:45:21 2010 for dune-common by  doxygen 1.6.3