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
00028
00029
00030 #ifndef _EXCEPTION_HPP_
00031 #define _EXCEPTION_HPP_
00032
00033 #include <ostream>
00034 #include <string>
00035 #include <sstream>
00036
00037 #include <cfloat>
00038 #include <climits>
00039 #include <cstdlib>
00040 const unsigned UNSIGNED_UNSET=UINT_MAX;
00041 const int INT_UNSET=INT_MAX;
00042 const double DOUBLE_UNSET=DBL_MAX;
00043
00050 class Exception
00051 {
00052 private:
00053 std::string mMessage;
00055 public:
00063 Exception(std::string message, std::string filename, const unsigned rLineNumber);
00064
00069 std::string GetMessage() const;
00070 };
00071
00072 #define EXCEPTION(message) throw Exception(message, __FILE__, __LINE__)
00073
00074 #define NEVER_REACHED EXCEPTION("Should have been impossible to reach this line of code")
00075
00076
00077
00078 #ifdef NDEBUG
00079 #define UNUSED_OPT(var) var=var
00080 #else
00081 #define UNUSED_OPT(var)
00082 #endif
00083
00084
00085 #define EXPECT0(cmd, arg) { \
00086 std::string _arg = (arg); \
00087 int ret = cmd(_arg.c_str()); \
00088 if (ret != 0) { \
00089 EXCEPTION("Failed to execute command: " #cmd "(" + _arg + ")"); \
00090 } }
00091
00092 #define IGNORE_RET(cmd, arg) { \
00093 std::string _arg = (arg); \
00094 int ret = cmd(_arg.c_str()); \
00095 ret = ret; \
00096 }
00097
00098 #endif // _EXCEPTION_HPP_