00001 #ifndef _STD_EXCEPT_HH_
00002 #define _STD_EXCEPT_HH_
00003
00004 #include <exception>
00005 #include <string>
00006
00007 using namespace std;
00008
00009 void handle_exception(const exception&);
00010
00011 class StandardException : public exception {
00012 public:
00013 StandardException(const string& fname = string(), int ln = 0,
00014 const string& msg = string())
00015 { MakeMessage(fname,ln,msg); BuildBacktrace(); }
00016 virtual ~StandardException() {}
00017 virtual const char *what() const { return message.c_str(); };
00018 protected:
00019 string message;
00020 string bt;
00021
00022 void MakeMessage(const string& file, int line, const string& msg);
00023 void BuildBacktrace();
00024 };
00025
00026
00027
00028 class StandardMemoryExhaustException : public StandardException {
00029 public:
00030 StandardMemoryExhaustException() : StandardException() {};
00031 StandardMemoryExhaustException(const string& fname, int ln,
00032 const string& msg = string())
00033 : StandardException(fname, ln, head()+msg) {}
00034 const char *head() const {
00035 return "Cannot allocate memory: Memory full.\n";};
00036 };
00037
00038 class StandardDivisionByZeroException : public StandardException {
00039 public:
00040 StandardDivisionByZeroException() : StandardException() {};
00041 StandardDivisionByZeroException(const string& fname, int ln,
00042 const string& msg = string())
00043 : StandardException(fname, ln, head()+msg) {}
00044 const char *head() const {return "Division by zero.\n";};
00045 };
00046
00047 #endif