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

Last change on this file since 79 was 64, checked in by umoeller, 24 years ago

Sources as for V0.9.11.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 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 "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 // PFNEXCONKILL pfnOnKill; // subroutine to call upon process/thread termination
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);
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 /********************************************************************
143 *
144 * Macros
145 *
146 ********************************************************************/
147
148 /* See except.c for explanations how to use these. */
149
150 #ifdef __NO_EXCEPTION_HANDLERS__
151 // exception handlers can completely be disabled
152 #define TRY_LOUD(excptstruct)
153 #else
154 #define TRY_LOUD(excptstruct) \
155 { \
156 EXCEPTSTRUCT excptstruct = {0}; \
157 excptstruct.RegRec2.pfnHandler = (PFN)excHandlerLoud; \
158 excptstruct.arc = DosSetExceptionHandler( \
159 (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
160 if (excptstruct.arc) \
161 if (G_pfnExcHookError) \
162 G_pfnExcHookError(__FILE__, __LINE__, __FUNCTION__, excptstruct.arc); \
163 else \
164 DosBeep(1000, 1000); \
165 excptstruct.ulExcpt = setjmp(excptstruct.RegRec2.jmpThread); \
166 if (excptstruct.ulExcpt == 0) \
167 {
168
169 #endif
170
171 #ifdef __NO_EXCEPTION_HANDLERS__
172 // exception handlers can completely be disabled
173 #define TRY_QUIET(excptstruct)
174 #else
175 #define TRY_QUIET(excptstruct) \
176 { \
177 EXCEPTSTRUCT excptstruct = {0}; \
178 excptstruct.RegRec2.pfnHandler = (PFN)excHandlerQuiet; \
179 excptstruct.arc = DosSetExceptionHandler( \
180 (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
181 if (excptstruct.arc) \
182 if (G_pfnExcHookError) \
183 G_pfnExcHookError(__FILE__, __LINE__, __FUNCTION__, excptstruct.arc); \
184 else \
185 DosBeep(1000, 1000); \
186 excptstruct.ulExcpt = setjmp(excptstruct.RegRec2.jmpThread); \
187 if (excptstruct.ulExcpt == 0) \
188 {
189
190 #endif
191
192 #ifdef __NO_EXCEPTION_HANDLERS__
193 // exception handlers can completely be disabled
194 #define CATCH(excptstruct) if (FALSE) {
195 #else
196 #define CATCH(excptstruct) \
197 DosUnsetExceptionHandler( \
198 (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
199 } /* end of TRY block */ \
200 else \
201 { /* exception occured: */ \
202 DosUnsetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2));
203 #endif
204
205 #ifdef __NO_EXCEPTION_HANDLERS__
206 // exception handlers can completely be disabled
207 #define END_CATCH() }
208 #else
209 #define END_CATCH() \
210 } /* end of exception-occured block */ \
211 }
212 #endif
213
214 /*
215 * CRASH:
216 * this macro is helpful for testing
217 * the exception handlers.
218 * This is not for general use. ;-)
219 */
220
221 #define CRASH {PSZ p = NULL; *p = 'a'; }
222
223#endif // EXCEPT_HEADER_INCLUDED
224
225#if __cplusplus
226}
227#endif
228
Note: See TracBrowser for help on using the repository browser.