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

Last change on this file since 37 was 14, checked in by umoeller, 25 years ago

Major updates; timers, LVM, miscellaneous.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 KB
Line 
1/* $Id: except.h 14 2000-12-09 19:19:42Z 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 // forward declaration
61 typedef struct _EXCEPTIONREGISTRATIONRECORD2 *PEXCEPTIONREGISTRATIONRECORD2;
62
63 // "OnKill" function prototype for EXCEPTIONREGISTRATIONRECORD2
64 // added V0.9.0 (99-10-22) [umoeller]
65 // removed V0.9.7 (2000-12-08) [umoeller]
66 // typedef VOID APIENTRY FNEXCONKILL(PEXCEPTIONREGISTRATIONRECORD2);
67 // typedef FNEXCONKILL *PFNEXCONKILL;
68
69 /*
70 *@@ EXCEPTIONREGISTRATIONRECORD2:
71 * replacement EXCEPTIONREGISTRATIONRECORD
72 * struct for thread exception handling.
73 *
74 *@@changed V0.9.0 (99-10-22) [umoeller]: pfnOnKill added
75 *@@changed V0.9.0 (99-10-22) [umoeller]: renamed from REGREC2
76 */
77
78 typedef struct _EXCEPTIONREGISTRATIONRECORD2
79 {
80 PVOID pNext; // as in EXCEPTIONREGISTRATIONRECORD
81 PFN pfnHandler; // as in EXCEPTIONREGISTRATIONRECORD
82 jmp_buf jmpThread; // additional buffer for setjmp
83 // PFNEXCONKILL pfnOnKill; // subroutine to call upon process/thread termination
84 PVOID pvUser; // user ptr
85 } EXCEPTIONREGISTRATIONRECORD2;
86
87 /*
88 *@@ EXCEPTSTRUCT:
89 * structure used with TRY_xxx macros.
90 */
91
92 typedef struct _EXCEPTSTRUCT
93 {
94 EXCEPTIONREGISTRATIONRECORD2 RegRec2;
95 ULONG ulExcpt; // != NULL if exception caught
96 APIRET arc; // rc of DosSetExceptionHandler
97 } EXCEPTSTRUCT, *PEXCEPTSTRUCT;
98
99 // function prototypes for exception hooks (V0.9.0)
100
101 // "open traplog file" hook
102 typedef FILE* APIENTRY FNEXCOPENFILE(VOID);
103 typedef FNEXCOPENFILE *PFNEXCOPENFILE;
104
105 // "exception" hook
106 typedef VOID APIENTRY FNEXCHOOK(FILE*, PTIB);
107 typedef FNEXCHOOK *PFNEXCHOOK;
108
109 // "error" hook
110 typedef VOID APIENTRY FNEXCHOOKERROR(const char *pcszFile,
111 ULONG ulLine,
112 const char *pcszFunction,
113 APIRET arc);
114 typedef FNEXCHOOKERROR *PFNEXCHOOKERROR;
115
116 /********************************************************************
117 *
118 * Prototypes
119 *
120 ********************************************************************/
121
122 VOID excRegisterHooks(PFNEXCOPENFILE pfnExcOpenFileNew,
123 PFNEXCHOOK pfnExcHookNew,
124 PFNEXCHOOKERROR pfnExcHookError,
125 BOOL fBeepOnExceptionNew);
126
127 ULONG _System excHandlerLoud(PEXCEPTIONREPORTRECORD pReportRec,
128 PEXCEPTIONREGISTRATIONRECORD2 pRegRec2,
129 PCONTEXTRECORD pContextRec,
130 PVOID pv);
131
132 ULONG _System excHandlerQuiet(PEXCEPTIONREPORTRECORD pReportRec,
133 PEXCEPTIONREGISTRATIONRECORD2 pRegRec2,
134 PCONTEXTRECORD pContextRec,
135 PVOID pv);
136
137 extern PFNEXCHOOKERROR G_pfnExcHookError;
138
139 /********************************************************************
140 *
141 * Macros
142 *
143 ********************************************************************/
144
145 /* See except.c for explanations how to use these. */
146
147 #ifdef __NO_EXCEPTION_HANDLERS__
148 // exception handlers can completely be disabled
149 #define TRY_LOUD(excptstruct)
150 #else
151 #define TRY_LOUD(excptstruct) \
152 { \
153 EXCEPTSTRUCT excptstruct = {0}; \
154 excptstruct.RegRec2.pfnHandler = (PFN)excHandlerLoud; \
155 excptstruct.arc = DosSetExceptionHandler( \
156 (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
157 if (excptstruct.arc) \
158 if (G_pfnExcHookError) \
159 G_pfnExcHookError(__FILE__, __LINE__, __FUNCTION__, excptstruct.arc); \
160 else \
161 DosBeep(1000, 1000); \
162 excptstruct.ulExcpt = setjmp(excptstruct.RegRec2.jmpThread); \
163 if (excptstruct.ulExcpt == 0) \
164 {
165
166 #endif
167
168 #ifdef __NO_EXCEPTION_HANDLERS__
169 // exception handlers can completely be disabled
170 #define TRY_QUIET(excptstruct)
171 #else
172 #define TRY_QUIET(excptstruct) \
173 { \
174 EXCEPTSTRUCT excptstruct = {0}; \
175 excptstruct.RegRec2.pfnHandler = (PFN)excHandlerQuiet; \
176 excptstruct.arc = DosSetExceptionHandler( \
177 (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
178 if (excptstruct.arc) \
179 if (G_pfnExcHookError) \
180 G_pfnExcHookError(__FILE__, __LINE__, __FUNCTION__, excptstruct.arc); \
181 else \
182 DosBeep(1000, 1000); \
183 excptstruct.ulExcpt = setjmp(excptstruct.RegRec2.jmpThread); \
184 if (excptstruct.ulExcpt == 0) \
185 {
186
187 #endif
188
189 #ifdef __NO_EXCEPTION_HANDLERS__
190 // exception handlers can completely be disabled
191 #define CATCH(excptstruct) if (FALSE) {
192 #else
193 #define CATCH(excptstruct) \
194 DosUnsetExceptionHandler( \
195 (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
196 } /* end of TRY block */ \
197 else \
198 { /* exception occured: */ \
199 DosUnsetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2));
200 #endif
201
202 #ifdef __NO_EXCEPTION_HANDLERS__
203 // exception handlers can completely be disabled
204 #define END_CATCH() }
205 #else
206 #define END_CATCH() \
207 } /* end of exception-occured block */ \
208 }
209 #endif
210
211 /*
212 * CRASH:
213 * this macro is helpful for testing
214 * the exception handlers.
215 * This is not for general use. ;-)
216 */
217
218 #define CRASH {PSZ p = NULL; *p = 'a'; }
219
220#endif // EXCEPT_HEADER_INCLUDED
221
222#if __cplusplus
223}
224#endif
225
Note: See TracBrowser for help on using the repository browser.