source: branches/branch-1-0/include/helpers/except.h@ 264

Last change on this file since 264 was 264, checked in by pr, 21 years ago

Fix spelling errors.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 KB
Line 
1
2/*
3 *@@sourcefile except.h:
4 * header file for except.c. See remarks there.
5 *
6 * Note: Version numbering in this file relates to XWorkplace version
7 * numbering.
8 *
9 *@@include #define INCL_DOSEXCEPTIONS
10 *@@include #define INCL_DOSPROCESS
11 *@@include #include <os2.h>
12 *@@include #include <stdio.h>
13 *@@include #include <setjmp.h>
14 *@@include #include "helpers\except.h"
15 */
16
17/*
18 * Copyright (C) 1999-2000 Ulrich M”ller.
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation, in version 2 as it comes in the COPYING
22 * file of the XFolder main distribution.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 */
28
29#if __cplusplus
30extern "C" {
31#endif
32
33#ifndef EXCEPT_HEADER_INCLUDED
34 #define EXCEPT_HEADER_INCLUDED
35
36 #if defined __IBMCPP__ || defined __IBMC__
37 #ifndef INCL_DOSEXCEPTIONS
38 #error except.h requires INCL_DOSEXCEPTIONS to be defined.
39 #endif
40 #ifndef INCL_DOSPROCESS
41 #error except.h requires INCL_DOSPROCESS to be defined.
42 #endif
43
44 #ifndef __stdio_h
45 #error except.h requires stdio.h to be included.
46 #endif
47 #ifndef __setjmp_h
48 #error except.h requires setjmp.h to be included.
49 #endif
50 #endif
51
52 /********************************************************************
53 *
54 * Declarations
55 *
56 ********************************************************************/
57
58 // forward declaration
59 typedef struct _EXCEPTIONREGISTRATIONRECORD2 *PEXCEPTIONREGISTRATIONRECORD2;
60
61 // "OnKill" function prototype for EXCEPTIONREGISTRATIONRECORD2
62 // added V0.9.0 (99-10-22) [umoeller]
63 // removed V0.9.7 (2000-12-08) [umoeller]
64 // typedef VOID APIENTRY FNEXCONKILL(PEXCEPTIONREGISTRATIONRECORD2);
65 // typedef FNEXCONKILL *PFNEXCONKILL;
66
67 /*
68 *@@ EXCEPTIONREGISTRATIONRECORD2:
69 * replacement EXCEPTIONREGISTRATIONRECORD
70 * struct for thread exception handling.
71 *
72 *@@changed V0.9.0 (99-10-22) [umoeller]: pfnOnKill added
73 *@@changed V0.9.0 (99-10-22) [umoeller]: renamed from REGREC2
74 */
75
76 typedef struct _EXCEPTIONREGISTRATIONRECORD2
77 {
78 PVOID pNext; // as in EXCEPTIONREGISTRATIONRECORD
79 PFN pfnHandler; // as in EXCEPTIONREGISTRATIONRECORD
80 jmp_buf jmpThread; // additional buffer for setjmp
81 EXCEPTIONREPORTRECORD err; // exception handlers copy the report rec here
82 PVOID pvUser; // user ptr
83 } EXCEPTIONREGISTRATIONRECORD2;
84
85 /*
86 *@@ EXCEPTSTRUCT:
87 * structure used with TRY_xxx macros.
88 */
89
90 typedef struct _EXCEPTSTRUCT
91 {
92 EXCEPTIONREGISTRATIONRECORD2 RegRec2;
93 ULONG ulExcpt; // != NULL if exception caught
94 APIRET arc; // rc of DosSetExceptionHandler
95 } EXCEPTSTRUCT, *PEXCEPTSTRUCT;
96
97 // function prototypes for exception hooks (V0.9.0)
98
99 // "open traplog file" hook
100 typedef FILE* APIENTRY FNEXCOPENFILE(VOID);
101 typedef FNEXCOPENFILE *PFNEXCOPENFILE;
102
103 // "exception" hook
104 typedef VOID APIENTRY FNEXCHOOK(FILE*, PTIB, ULONG); // V0.9.16 (2001-12-02) [pr]
105 typedef FNEXCHOOK *PFNEXCHOOK;
106
107 // "error" hook
108 typedef VOID APIENTRY FNEXCHOOKERROR(const char *pcszFile,
109 ULONG ulLine,
110 const char *pcszFunction,
111 APIRET arc);
112 typedef FNEXCHOOKERROR *PFNEXCHOOKERROR;
113
114 /********************************************************************
115 *
116 * Prototypes
117 *
118 ********************************************************************/
119
120 VOID _Optlink excExplainException(FILE *file,
121 PSZ pszHandlerName,
122 PEXCEPTIONREPORTRECORD pReportRec,
123 PCONTEXTRECORD pContextRec);
124
125 VOID excRegisterHooks(PFNEXCOPENFILE pfnExcOpenFileNew,
126 PFNEXCHOOK pfnExcHookNew,
127 PFNEXCHOOKERROR pfnExcHookError,
128 BOOL fBeepOnExceptionNew);
129
130 ULONG _System excHandlerLoud(PEXCEPTIONREPORTRECORD pReportRec,
131 PEXCEPTIONREGISTRATIONRECORD2 pRegRec2,
132 PCONTEXTRECORD pContextRec,
133 PVOID pv);
134
135 ULONG _System excHandlerQuiet(PEXCEPTIONREPORTRECORD pReportRec,
136 PEXCEPTIONREGISTRATIONRECORD2 pRegRec2,
137 PCONTEXTRECORD pContextRec,
138 PVOID pv);
139
140 extern PFNEXCHOOKERROR G_pfnExcHookError;
141
142 extern ULONG G_ulExplainExceptionRunning;
143
144 /********************************************************************
145 *
146 * Macros
147 *
148 ********************************************************************/
149
150 /* See except.c for explanations how to use these. */
151
152 #ifdef __NO_EXCEPTION_HANDLERS__
153 // exception handlers can completely be disabled
154 #define TRY_LOUD(excptstruct)
155 #else
156 #ifdef __NO_LOUD_EXCEPTION_HANDLERS__
157 #define TRY_LOUD(e) TRY_QUIET(e)
158 #else // __NO_LOUD_EXCEPTION_HANDLERS__
159 #define TRY_LOUD(excptstruct) \
160 { \
161 EXCEPTSTRUCT excptstruct = {0}; \
162 excptstruct.RegRec2.pfnHandler = (PFN)excHandlerLoud; \
163 excptstruct.arc = DosSetExceptionHandler( \
164 (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
165 if (excptstruct.arc) \
166 if (G_pfnExcHookError) \
167 G_pfnExcHookError(__FILE__, __LINE__, __FUNCTION__, excptstruct.arc); \
168 else \
169 DosBeep(1000, 1000); \
170 excptstruct.ulExcpt = setjmp(excptstruct.RegRec2.jmpThread); \
171 if (excptstruct.ulExcpt == 0) \
172 {
173
174 #endif // __NO_LOUD_EXCEPTION_HANDLERS__
175 #endif
176
177 #ifdef __NO_EXCEPTION_HANDLERS__
178 // exception handlers can completely be disabled
179 #define TRY_QUIET(excptstruct)
180 #else
181 #define TRY_QUIET(excptstruct) \
182 { \
183 EXCEPTSTRUCT excptstruct = {0}; \
184 excptstruct.RegRec2.pfnHandler = (PFN)excHandlerQuiet; \
185 excptstruct.arc = DosSetExceptionHandler( \
186 (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
187 if (excptstruct.arc) \
188 if (G_pfnExcHookError) \
189 G_pfnExcHookError(__FILE__, __LINE__, __FUNCTION__, excptstruct.arc); \
190 else \
191 DosBeep(1000, 1000); \
192 excptstruct.ulExcpt = setjmp(excptstruct.RegRec2.jmpThread); \
193 if (excptstruct.ulExcpt == 0) \
194 {
195
196 #endif
197
198 #ifdef __NO_EXCEPTION_HANDLERS__
199 // exception handlers can completely be disabled
200 #define CATCH(excptstruct) if (FALSE) {
201 #else
202 #define CATCH(excptstruct) \
203 DosUnsetExceptionHandler( \
204 (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
205 } /* end of TRY block */ \
206 else \
207 { /* exception occurred: */ \
208 DosUnsetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2));
209 #endif
210
211 #ifdef __NO_EXCEPTION_HANDLERS__
212 // exception handlers can completely be disabled
213 #define END_CATCH() }
214 #else
215 #define END_CATCH() \
216 } /* end of exception-occurred block */ \
217 }
218 #endif
219
220 /*
221 * CRASH:
222 * this macro is helpful for testing
223 * the exception handlers.
224 * This is not for general use. ;-)
225 */
226
227 #define CRASH {PSZ p = NULL; *p = 'a'; }
228
229#endif // EXCEPT_HEADER_INCLUDED
230
231#if __cplusplus
232}
233#endif
234
Note: See TracBrowser for help on using the repository browser.