angel_exceptions.hpp

Go to the documentation of this file.
00001 // $Id: angel_exceptions.hpp,v 1.1 2003/06/11 16:30:05 gottschling Exp $
00002 
00003 #ifndef         _angel_exceptions_include_
00004 #define         _angel_exceptions_include_
00005 
00006 #include <string>
00007 #include <iostream>
00008 #include <sstream>
00009 
00010 namespace angel {
00011 
00012   class base_exception {
00013   protected:
00014     std::string reason;
00015   public:
00017     base_exception (std::string filename, int linenumber, std::string what) {
00018       std::ostringstream stream;
00019       stream << "In file " << filename << " at line " << linenumber << ": " << what; 
00020       reason= stream.str(); }
00022     void say_reason () {
00023       std::cerr << reason << std::endl;}
00025     const std::string& what_reason () const {return reason;}
00026   };
00027 
00028   class io_exception : public base_exception {
00029   public:
00030     io_exception (std::string filename, int linenumber, std::string what) 
00031       : base_exception (filename, linenumber, what) {}
00032   };
00033 
00034   class consistency_exception : public base_exception {
00035   public:
00036     consistency_exception (std::string filename, int linenumber, std::string what) 
00037       : base_exception (filename, linenumber, what) {}
00038   };
00039   
00040 
00041 #ifndef NDEBUG
00042 #define THROW_DEBUG_EXCEPT_MACRO(Test,Exception,Message) \
00043 { \
00044 if (Test) { \
00045   throw Exception(__FILE__, __LINE__, Message); }\
00046 }
00047 #else
00048 #define THROW_DEBUG_EXCEPT_MACRO(Test,Exception,Message)
00049 #endif
00050 
00051 #define THROW_EXCEPT_MACRO(Test,Exception,Message) \
00052 { \
00053 if (Test) { \
00054   throw Exception(__FILE__, __LINE__, Message); }\
00055 }
00056 
00057 
00058 } // namespace angel
00059 
00060 
00061 #endif  // _angel_exceptions_include_
00062 

Generated on Wed Mar 11 10:33:11 2009 for angel by  doxygen 1.5.3