00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _UXERR_HPP_
00019 #define _UXERR_HPP_
00020
00021 #include <exception>
00022 #include <iostream>
00023
00024 #define EC_CAUGHT(e)\
00025 ec_push(__func__, __FILE__, __LINE__, "EC_CAUGHT",\
00026 e.get_code(), e.get_type());
00027
00028 #define EC_EXIT(e)\
00029 {\
00030 EC_CAUGHT(e)\
00031 ::exit(EXIT_FAILURE);\
00032 }
00033
00034 #define EC__EXIT(e)\
00035 {\
00036 EC_CAUGHT(e)\
00037 EC_FLUSH("EC__EXIT")\
00038 ::_exit(EXIT_FAILURE);\
00039 }
00040
00041 #define EC_CATCH(s)\
00042 try { s; } catch (Error e) { EC_EXIT(e) }
00043
00044 namespace Ux {
00045
00046
00047
00048
00049 class Error : public exception {
00050 protected:
00051 EC_ERRTYPE e_type;
00052 int e_code;
00053 char str[50];
00054 public:
00055 Error(int c = 0, EC_ERRTYPE t = EC_ERRNO)
00056 : e_type(t), e_code(c)
00057 { }
00058 void set(int c, EC_ERRTYPE t = EC_ERRNO)
00059 { e_type = t; e_code = c; }
00060 EC_ERRTYPE get_type(void) const
00061 { return e_type; }
00062 int get_code(void) const
00063 { return e_code; }
00064 operator int() const
00065 { return e_code; }
00066 operator const char*() const
00067 { return what(); }
00068 virtual const char *what() const throw();
00069 };
00070
00071
00072
00073
00074
00075 std::ostream& operator<<(std::ostream& s, const Error& e);
00076
00077
00078 }
00079
00080 #endif // _UXERR_HPP_