source: trunk/include/helpers/except.h@ 10

Last change on this file since 10 was 7, checked in by umoeller, 25 years ago

Initial checkin of helpers code, which used to be in WarpIN.

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