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

Last change on this file since 52 was 41, checked in by umoeller, 24 years ago

Updated timers.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 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 excRegisterHooks(PFNEXCOPENFILE pfnExcOpenFileNew,
121 PFNEXCHOOK pfnExcHookNew,
122 PFNEXCHOOKERROR pfnExcHookError,
123 BOOL fBeepOnExceptionNew);
124
125 ULONG _System excHandlerLoud(PEXCEPTIONREPORTRECORD pReportRec,
126 PEXCEPTIONREGISTRATIONRECORD2 pRegRec2,
127 PCONTEXTRECORD pContextRec,
128 PVOID pv);
129
130 ULONG _System excHandlerQuiet(PEXCEPTIONREPORTRECORD pReportRec,
131 PEXCEPTIONREGISTRATIONRECORD2 pRegRec2,
132 PCONTEXTRECORD pContextRec,
133 PVOID pv);
134
135 extern PFNEXCHOOKERROR G_pfnExcHookError;
136
137 /********************************************************************
138 *
139 * Macros
140 *
141 ********************************************************************/
142
143 /* See except.c for explanations how to use these. */
144
145 #ifdef __NO_EXCEPTION_HANDLERS__
146 // exception handlers can completely be disabled
147 #define TRY_LOUD(excptstruct)
148 #else
149 #define TRY_LOUD(excptstruct) \
150 { \
151 EXCEPTSTRUCT excptstruct = {0}; \
152 excptstruct.RegRec2.pfnHandler = (PFN)excHandlerLoud; \
153 excptstruct.arc = DosSetExceptionHandler( \
154 (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
155 if (excptstruct.arc) \
156 if (G_pfnExcHookError) \
157 G_pfnExcHookError(__FILE__, __LINE__, __FUNCTION__, excptstruct.arc); \
158 else \
159 DosBeep(1000, 1000); \
160 excptstruct.ulExcpt = setjmp(excptstruct.RegRec2.jmpThread); \
161 if (excptstruct.ulExcpt == 0) \
162 {
163
164 #endif
165
166 #ifdef __NO_EXCEPTION_HANDLERS__
167 // exception handlers can completely be disabled
168 #define TRY_QUIET(excptstruct)
169 #else
170 #define TRY_QUIET(excptstruct) \
171 { \
172 EXCEPTSTRUCT excptstruct = {0}; \
173 excptstruct.RegRec2.pfnHandler = (PFN)excHandlerQuiet; \
174 excptstruct.arc = DosSetExceptionHandler( \
175 (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
176 if (excptstruct.arc) \
177 if (G_pfnExcHookError) \
178 G_pfnExcHookError(__FILE__, __LINE__, __FUNCTION__, excptstruct.arc); \
179 else \
180 DosBeep(1000, 1000); \
181 excptstruct.ulExcpt = setjmp(excptstruct.RegRec2.jmpThread); \
182 if (excptstruct.ulExcpt == 0) \
183 {
184
185 #endif
186
187 #ifdef __NO_EXCEPTION_HANDLERS__
188 // exception handlers can completely be disabled
189 #define CATCH(excptstruct) if (FALSE) {
190 #else
191 #define CATCH(excptstruct) \
192 DosUnsetExceptionHandler( \
193 (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
194 } /* end of TRY block */ \
195 else \
196 { /* exception occured: */ \
197 DosUnsetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2));
198 #endif
199
200 #ifdef __NO_EXCEPTION_HANDLERS__
201 // exception handlers can completely be disabled
202 #define END_CATCH() }
203 #else
204 #define END_CATCH() \
205 } /* end of exception-occured block */ \
206 }
207 #endif
208
209 /*
210 * CRASH:
211 * this macro is helpful for testing
212 * the exception handlers.
213 * This is not for general use. ;-)
214 */
215
216 #define CRASH {PSZ p = NULL; *p = 'a'; }
217
218#endif // EXCEPT_HEADER_INCLUDED
219
220#if __cplusplus
221}
222#endif
223
Note: See TracBrowser for help on using the repository browser.