Foxit PDF SDK
fx_exception.h
浏览该文件的文档.
1 
20 #ifndef _FX_EXCEPTION_H_
21 #define _FX_EXCEPTION_H_
22 
23 #define FX_SETJMP(BUF) setjmp(BUF)
24 #define FX_LONGJMP(BUF, VAL) longjmp(BUF, VAL)
25 #define FX_JMP_BUF jmp_buf
26 
27 /* @brief JMP 深度默认 512。*/
28 #define FX_JMP_DEPTH 512
29 
30 #ifndef _FX_ERROR_H_
31 #include "fx_error.h"
32 #endif
33 
34 #ifndef _FX_SYSTEM_H_
35 #include "fx_system.h"
36 #endif
37 
38 #ifndef _FX_BASIC_H_
39 #include "fx_basic.h"
40 #endif
41 
42 class CFX_Exception;
43 class CFX_JmpStack;
44 
48 class CFX_JmpStack : public CFX_Object
49 {
50  public:
51  CFX_JmpStack() : code(0)
52  {
53  FXSYS_memset(&buffer, 0 ,sizeof(buffer));
54  }
55 
56  int code;
57  FX_JMP_BUF buffer;
58 };
59 
60 class CFX_Exception : public CFX_Object
61 {
62  public:
63  CFX_Exception();
64  ~CFX_Exception();
65 
66  FX_BOOL Catch(int value);
67  FX_BOOL CatchAll();
68  void EndTry();
69 
70  protected:
71  FX_BOOL m_bCatched;
72 };
73 
74 #ifdef _FX_SUPPORT_EXCEPTION_
75 //*****************************************************************************
76 //* 异常宏。
77 //*****************************************************************************
93 
94 #define FX_TRY \
95  { \
96  CFX_Exception __exception; \
97  if (FX_Push_Try(FX_Thread_GetExceptionContext()->m_pErrContext) && (FX_Thread_GetExceptionContext()->m_pErrContext->stack[FX_Thread_GetExceptionContext()->m_pErrContext->top].code = \
98  FX_SETJMP(FX_Thread_GetExceptionContext()->m_pErrContext->stack[FX_Thread_GetExceptionContext()->m_pErrContext->top].buffer)) == 0)
99 
100 #define FX_ALWAYS() \
101  if (1)
102 
103 #define FX_CATCH(value) \
104  if (__exception.Catch(value))
105 
106 #define FX_CATCHALL() \
107  if (__exception.CatchAll())
108 
109 #define FX_ENDTRY \
110  __exception.EndTry(); \
111  }
112 
113 //这将在抛出错误值之前抛出。
114 #define FX_CONTINUETHROW FX_ContinueThrow()
115 
116 //这将获取当前捕获错误值。
117 #define FX_GETCATCHCODE FX_GetCatchCode()
118 
126 void FX_Throw(int iErrCode);
127 void FX_ContinueThrow();
128 
133 int FX_GetCatchCode();
134 
135 #endif //_FX_SUPPORT_EXCEPTION_
136 
138 class CFX_ExceptionErrorContext : public CFX_Object
139 {
140  public:
142 
143  void Initialize();
144  void Finalize();
145 
146  int top;
147  CFX_JmpStack *stack;
148 };
149 
150 class CFX_ExceptionContext : public CFX_Object
151 {
152  public:
153  CFX_ExceptionContext() : m_pErrContext(NULL) {}
154 
155  void Initialize();
156  void Finalize();
157 
158  CFX_ExceptionErrorContext* m_pErrContext;
159 };
160 
161 //*****************************************************************************
162 //* 以下函数将被前面的宏隐式调用。
163 //* 请不要直接使用。
164 //*****************************************************************************
165 FX_BOOL FX_Push_Try(CFX_ExceptionErrorContext* pErrContext);
166 
167 #endif //_FX_EXCEPTION_H_
168 
Definition: fx_exception.h:48
错误处理的头文件。
Definition: fx_exception.h:138
int FX_BOOL
布尔变量(应为TRUE或FALSE)。
Definition: fx_system.h:691
#define FXSYS_memset
使用给定字符初始化缓冲区。
Definition: fx_system.h:1125
基本数据类的头文件。
#define NULL
空指针值。
Definition: fx_system.h:792
系统相关定义的头文件。