3 *@@sourcefile except.h:
4 * header file for except.c. See remarks there.
6 * Note: Version numbering in this file relates to XWorkplace version
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"
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.
33 #ifndef EXCEPT_HEADER_INCLUDED
34 #define EXCEPT_HEADER_INCLUDED
36 #if defined __IBMCPP__ || defined __IBMC__
37 #ifndef INCL_DOSEXCEPTIONS
38 #error except.h requires INCL_DOSEXCEPTIONS to be defined.
40 #ifndef INCL_DOSPROCESS
41 #error except.h requires INCL_DOSPROCESS to be defined.
45 #error except.h requires stdio.h to be included.
48 #error except.h requires setjmp.h to be included.
52 /********************************************************************
56 ********************************************************************/
58 // forward declaration
59 typedef struct _EXCEPTIONREGISTRATIONRECORD2
*PEXCEPTIONREGISTRATIONRECORD2
;
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;
68 *@@ EXCEPTIONREGISTRATIONRECORD2:
69 * replacement EXCEPTIONREGISTRATIONRECORD
70 * struct for thread exception handling.
72 *@@changed V0.9.0 (99-10-22) [umoeller]: pfnOnKill added
73 *@@changed V0.9.0 (99-10-22) [umoeller]: renamed from REGREC2
76 typedef struct _EXCEPTIONREGISTRATIONRECORD2
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
;
87 * structure used with TRY_xxx macros.
90 typedef struct _EXCEPTSTRUCT
92 EXCEPTIONREGISTRATIONRECORD2 RegRec2
;
93 ULONG ulExcpt
; // != NULL if exception caught
94 APIRET arc
; // rc of DosSetExceptionHandler
95 } EXCEPTSTRUCT
, *PEXCEPTSTRUCT
;
97 // function prototypes for exception hooks (V0.9.0)
99 // "open traplog file" hook
100 typedef FILE* APIENTRY
FNEXCOPENFILE(VOID
);
101 typedef FNEXCOPENFILE
*PFNEXCOPENFILE
;
104 typedef VOID APIENTRY
FNEXCHOOK(FILE*, PTIB
, ULONG
); // V0.9.16 (2001-12-02) [pr]
105 typedef FNEXCHOOK
*PFNEXCHOOK
;
108 typedef VOID APIENTRY
FNEXCHOOKERROR(const char *pcszFile
,
110 const char *pcszFunction
,
112 typedef FNEXCHOOKERROR
*PFNEXCHOOKERROR
;
114 /********************************************************************
118 ********************************************************************/
120 VOID
excExplainException(FILE *file
,
122 PEXCEPTIONREPORTRECORD pReportRec
,
123 PCONTEXTRECORD pContextRec
);
125 VOID
excRegisterHooks(PFNEXCOPENFILE pfnExcOpenFileNew
,
126 PFNEXCHOOK pfnExcHookNew
,
127 PFNEXCHOOKERROR pfnExcHookError
,
128 BOOL fBeepOnExceptionNew
);
130 ULONG _System
excHandlerLoud(PEXCEPTIONREPORTRECORD pReportRec
,
131 PEXCEPTIONREGISTRATIONRECORD2 pRegRec2
,
132 PCONTEXTRECORD pContextRec
,
135 ULONG _System
excHandlerQuiet(PEXCEPTIONREPORTRECORD pReportRec
,
136 PEXCEPTIONREGISTRATIONRECORD2 pRegRec2
,
137 PCONTEXTRECORD pContextRec
,
140 extern PFNEXCHOOKERROR G_pfnExcHookError
;
142 extern ULONG G_ulExplainExceptionRunning
;
144 /********************************************************************
148 ********************************************************************/
150 /* See except.c for explanations how to use these. */
152 #ifdef __NO_EXCEPTION_HANDLERS__
153 // exception handlers can completely be disabled
154 #define TRY_LOUD(excptstruct)
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) \
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); \
169 DosBeep(1000, 1000); \
170 excptstruct.ulExcpt = setjmp(excptstruct.RegRec2.jmpThread); \
171 if (excptstruct.ulExcpt == 0) \
174 #endif // __NO_LOUD_EXCEPTION_HANDLERS__
177 #ifdef __NO_EXCEPTION_HANDLERS__
178 // exception handlers can completely be disabled
179 #define TRY_QUIET(excptstruct)
181 #define TRY_QUIET(excptstruct) \
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); \
191 DosBeep(1000, 1000); \
192 excptstruct.ulExcpt = setjmp(excptstruct.RegRec2.jmpThread); \
193 if (excptstruct.ulExcpt == 0) \
198 #ifdef __NO_EXCEPTION_HANDLERS__
199 // exception handlers can completely be disabled
200 #define CATCH(excptstruct) if (FALSE) {
202 #define CATCH(excptstruct) \
203 DosUnsetExceptionHandler( \
204 (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
205 } /* end of TRY block */ \
207 { /* exception occured: */ \
208 DosUnsetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2));
211 #ifdef __NO_EXCEPTION_HANDLERS__
212 // exception handlers can completely be disabled
213 #define END_CATCH() }
215 #define END_CATCH() \
216 } /* end of exception-occured block */ \
222 * this macro is helpful for testing
223 * the exception handlers.
224 * This is not for general use. ;-)
227 #define CRASH {PSZ p = NULL; *p = 'a'; }
229 #endif // EXCEPT_HEADER_INCLUDED