[18] | 1 | /**
|
---|
| 2 | * CRXException.h
|
---|
| 3 | */
|
---|
| 4 | #ifndef __CRXEXCEPTION_H__
|
---|
| 5 | #define __CRXEXCEPTION_H__
|
---|
| 6 |
|
---|
| 7 | #include <string>
|
---|
[19] | 8 | #include <stdarg.h>
|
---|
[18] | 9 |
|
---|
| 10 | #ifdef _WIN32
|
---|
| 11 | # define __func__ __FUNCTION__
|
---|
| 12 | #endif
|
---|
| 13 |
|
---|
[35] | 14 | #ifdef _DEBUG
|
---|
| 15 | #include <stdio.h>
|
---|
| 16 | #include <ctype.h>
|
---|
| 17 | #define CRX_DEBUG_TRACE(FMT, ...) \
|
---|
| 18 | do{ \
|
---|
| 19 | fprintf(stderr,"[DEBUG][%s %s(%d)] ",__FILE__,__func__,__LINE__); \
|
---|
| 20 | fprintf(stderr,FMT,##__VA_ARGS__); \
|
---|
| 21 | }while(0)
|
---|
| 22 | #define CRX_DEBUG_TRACE_BIN(__VAL,__LEN,FMT,...) \
|
---|
| 23 | CRX_DEBUG_TRACE(FMT,##__VA_ARGS__); \
|
---|
| 24 | do{ \
|
---|
| 25 | int __i, __j; \
|
---|
| 26 | unsigned char * __U_V = (unsigned char *)__VAL; \
|
---|
| 27 | for (__i=0 ; __i<__LEN; __i+=16) \
|
---|
| 28 | { \
|
---|
| 29 | fprintf(stderr, "[DEBUG][%s %s(%d)] ",__FILE__,__func__,__LINE__); \
|
---|
| 30 | fprintf(stderr, "%06x : ", __i); \
|
---|
| 31 | for (__j=0 ; __j<16 ; __j++) \
|
---|
| 32 | { \
|
---|
| 33 | if (__i+__j < __LEN) \
|
---|
| 34 | fprintf(stderr, "%02x ", __U_V[__i+__j]); \
|
---|
| 35 | else \
|
---|
| 36 | fprintf(stderr, " "); \
|
---|
| 37 | } \
|
---|
| 38 | fprintf(stderr," "); \
|
---|
| 39 | for (__j=0 ; __j<16 ; __j++) \
|
---|
| 40 | { \
|
---|
| 41 | if (__i+__j < __LEN) \
|
---|
| 42 | fprintf(stderr,"%c", \
|
---|
| 43 | ' ' <= __U_V[__i+__j] && __U_V[__i+__j] <= '~' ? __U_V[__i+__j] : '.'); \
|
---|
| 44 | } \
|
---|
| 45 | fprintf(stderr,"\n"); \
|
---|
| 46 | } \
|
---|
| 47 | }while(0)
|
---|
| 48 | #endif
|
---|
| 49 |
|
---|
| 50 | #define CRX_ERROR_SET(__CODE,__FMT,...) \
|
---|
[19] | 51 | do { \
|
---|
[35] | 52 | SetErrorCode (__CODE); \
|
---|
[19] | 53 | SetErrorMessage (__FILE__,__func__,__LINE__,__FMT,##__VA_ARGS__); \
|
---|
[18] | 54 | } while (0)
|
---|
| 55 |
|
---|
[35] | 56 | #define CRX_ADD_SUBCLASS_ERROR(__SUB_CLASS) \
|
---|
[19] | 57 | do { \
|
---|
[35] | 58 | AddMessage (__SUB_CLASS.GetErrorMessage ().c_str ()); \
|
---|
[19] | 59 | } while (0)
|
---|
| 60 |
|
---|
[61] | 61 |
|
---|
| 62 | #define CRX_SYSTEM_ERROR() CRXException::GetSystemErrorCode ()
|
---|
| 63 |
|
---|
[18] | 64 | class CRXException
|
---|
| 65 | {
|
---|
| 66 | private:
|
---|
| 67 | std::string mMessage;
|
---|
| 68 | int mCode;
|
---|
| 69 |
|
---|
| 70 | public:
|
---|
[24] | 71 | CRXException (void);
|
---|
| 72 | virtual ~CRXException (void);
|
---|
[18] | 73 |
|
---|
| 74 | public:
|
---|
[61] | 75 | static int GetSystemErrorCode (void);
|
---|
| 76 |
|
---|
| 77 | public:
|
---|
[18] | 78 | /* get */
|
---|
| 79 | int GetErrorCode (void) const;
|
---|
| 80 |
|
---|
| 81 | std::string GetErrorMessage (void) const;
|
---|
| 82 |
|
---|
| 83 | /* set */
|
---|
| 84 | void SetErrorCode (const int aCode);
|
---|
| 85 |
|
---|
| 86 | void SetErrorMessage (const char * aFile,
|
---|
| 87 | const char * aFunction,
|
---|
| 88 | const int aLine,
|
---|
| 89 | const char * aFormat, ...);
|
---|
| 90 |
|
---|
| 91 | std::string MakeErrorMessage (const char * aFile,
|
---|
| 92 | const char * aFunction,
|
---|
| 93 | const int aLine,
|
---|
| 94 | const char * aFormat,
|
---|
| 95 | va_list aVaList);
|
---|
[19] | 96 |
|
---|
| 97 | void AddMessage (const char * aMessage);
|
---|
[18] | 98 | };
|
---|
| 99 |
|
---|
[61] | 100 | #endif // #ifndef __CRXEXCEPTION_H__
|
---|