Exception.h

00001 #ifndef gridripper_lang_Exception_h
00002 #define gridripper_lang_Exception_h
00003 
00004 #include <exception>
00005 #include <string>
00006 
00007 namespace gridripper {
00008 
00009 using namespace std;
00010 
00018 class Exception: public exception
00019 {
00020 protected:
00022     char* message;
00023 
00025     char* trace;
00026 
00027 public:
00031     Exception(const Exception& other);
00032 
00038     Exception(const string& msg, const string& where);
00039 
00045     Exception(const exception& orig, const string& where);
00046 
00053     Exception(const exception& orig, const string& msg, const string& where);
00054 
00055     virtual ~Exception() throw() {
00056         // this function must be inline because of mysterious segmentation
00057         // fault on IRIX 6.5.19 + MIPSpro CC 7.4
00058         delete [] message;
00059         delete [] trace;
00060     }
00061 
00063     void addLocation(const string& where);
00064 
00066     virtual const char* what() const throw() { return message; }
00067 
00069     virtual const char* getTrace() const { return trace; }
00070 
00071 protected:
00073     Exception();
00074 
00079     void addTraceIfPossible(const exception& ex);
00080 
00081 private:
00083     void init(const string& msg, const string& where);
00084 };
00085 
00086 } // namespace gridripper
00087 
00088 #endif /* gridripper_lang_Exception_h */