angel  mercurial changeset:
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 #############################################################
00004 # This file is part of angel released under the BSD license #
00005 # The full COPYRIGHT notice can be found in the top         #
00006 # level directory of the angel distribution                 #
00007 #############################################################
00008 */
00009 
00010 
00011 #ifndef         _angel_exceptions_include_
00012 #define         _angel_exceptions_include_
00013 
00014 #include <string>
00015 #include <iostream>
00016 #include <sstream>
00017 
00018 namespace angel {
00019 
00020   class base_exception {
00021   protected:
00022     std::string reason;
00023   public:
00025     base_exception (std::string filename, int linenumber, std::string what) {
00026       std::ostringstream stream;
00027       stream << "In file " << filename << " at line " << linenumber << ": " << what; 
00028       reason= stream.str(); }
00030     void say_reason () {
00031       std::cerr << reason << std::endl;}
00033     const std::string& what_reason () const {return reason;}
00034   };
00035 
00036   class io_exception : public base_exception {
00037   public:
00038     io_exception (std::string filename, int linenumber, std::string what) 
00039       : base_exception (filename, linenumber, what) {}
00040   };
00041 
00042   class consistency_exception : public base_exception {
00043   public:
00044     consistency_exception (std::string filename, int linenumber, std::string what) 
00045       : base_exception (filename, linenumber, what) {}
00046   };
00047   
00048 
00049 #ifndef NDEBUG
00050 #define THROW_DEBUG_EXCEPT_MACRO(Test,Exception,Message) \
00051 { \
00052 if (Test) { \
00053   throw Exception(__FILE__, __LINE__, Message); }\
00054 }
00055 #else
00056 #define THROW_DEBUG_EXCEPT_MACRO(Test,Exception,Message)
00057 #endif
00058 
00059 #define THROW_EXCEPT_MACRO(Test,Exception,Message) \
00060 { \
00061 if (Test) { \
00062   throw Exception(__FILE__, __LINE__, Message); }\
00063 }
00064 
00065 
00066 } // namespace angel
00067 
00068 
00069 #endif  // _angel_exceptions_include_
00070 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines