00001 #ifndef __EXCEPTION_H 00002 #define __EXCEPTION_H 00003 00004 #include <string> 00005 #include <iostream> 00006 using namespace std; 00007 00008 //------------------------------------------------------------------------------------------------ 00009 // Exception container 00010 //------------------------------------------------------------------------------------------------ 00011 00012 class Exception 00013 { 00014 private: 00015 00016 string message; 00017 00018 public: 00019 00020 Exception() { message="No message"; } 00021 Exception(const string &mex) { message=mex; } 00022 Exception(const char *format, ... ); 00023 00024 const char *GetMessage() const { return message.c_str(); } 00025 void PrintMessage() const { cerr<<message<<'\n'; } 00026 00027 static void Throw() { throw new Exception(); } 00028 static void Throw(const string &mex) { throw new Exception(mex); } 00029 static void Throw(const char *const format,...); 00030 static void Assert(bool condition) { if(!condition) throw new Exception(); } 00031 static void Assert(bool condition, const char *const format,...); 00032 static void Assert(bool condition, const string &mex) { if(!condition) throw new Exception(mex); } 00033 }; 00034 00035 #endif
1.5.1