Grafalgo
Library of useful data structures and algorithms
|
00001 00009 #ifndef EXCEPTIONS_H 00010 #define EXCEPTIONS_H 00011 00012 using namespace std; 00013 00014 namespace grafalgo { 00015 00024 class Exception { 00025 public: 00030 Exception(const string& s) { xStr = "Exception: " + s; } 00031 00036 string& toString(string& s) { s = xStr; return s; } 00037 00038 friend ostream& operator<<(ostream& out, Exception& e) { 00039 string s; return out << e.toString(s); 00040 } 00041 00042 protected: 00043 string xStr; 00044 }; 00045 00047 class IllegalArgumentException : public Exception { 00048 public: 00053 IllegalArgumentException(string& s) : 00054 Exception("IllegalArgumentException: " + s) { 00055 cerr << s; 00056 } 00057 }; 00058 00063 class OutOfSpaceException : public Exception { 00064 public: 00069 OutOfSpaceException(string& s) : 00070 Exception("OutOfSpaceException: " + s) { 00071 cerr << s; 00072 } 00073 }; 00074 00078 class InputException : public Exception { 00079 public: 00084 InputException(string& s) : Exception("InputException: " + s) { 00085 cerr << s; 00086 } 00087 }; 00088 00089 } // ending namespace 00090 #endif