Exception.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef exception_hh
00028 #define exception_hh
00029
00030 #include <string>
00031 #include <sstream>
00032 #include <exception>
00033
00034
00035 #ifdef NDEBUG
00036 const bool debug = false;
00037 #else
00038 const bool debug = true;
00039 #endif
00040
00041 class E_Exception;
00042
00043
00047 class E_Exception: std::exception {
00048 public:
00053 E_Exception(const std::string& L = "", const std::string& M = "")
00054 : m_msg( M ), m_loc( L ) {}
00055
00056 virtual ~E_Exception() throw() {};
00060 virtual const char * local() { return m_loc.c_str(); }
00064 virtual const char * what() const throw() { return m_msg.c_str(); }
00065
00066 protected:
00067 std::string m_msg;
00068 std::string m_loc;
00070 };
00071
00072
00073 inline std::ostream&
00074 operator<<( std::ostream& o, const E_Exception& e )
00075 {
00076 o << '\n' << "> Error: " << e.what() << std::endl;
00077 return o;
00078 }
00079
00080
00081 class E_NoInputFiles : public E_Exception {
00082 public:
00083 E_NoInputFiles ( const std::string& loc = "" )
00084 : E_Exception (loc, "No input to process") {};
00085 };
00086
00087
00088 class E_BigInput : public E_Exception {
00089 public:
00090 E_BigInput ( const std::string& loc = "" )
00091 : E_Exception (loc, "Too many input files/items") {};
00092 };
00093
00094
00095 class E_NoTarget : public E_Exception {
00096 public:
00097 E_NoTarget (const std::string& app = "gaffitter"): E_Exception ("",
00098 "Missing '--target' (Try '"+app+" -h' for more information)") {};
00099 };
00100
00101
00102 template<class X, class A> inline void Assert(A expression)
00103 {
00104 if (debug && !expression) throw X();
00105 }
00106
00107 inline void Assert(bool expression)
00108 {
00109 Assert<E_Exception>(expression);
00110 }
00111
00112
00113 #endif