1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 *@@sourcefile except.h:
30 * header file for except.c. See remarks there.
32 * Note: Version numbering in this file relates to XWorkplace version
35 *@@include #define INCL_DOSEXCEPTIONS
36 *@@include #define INCL_DOSPROCESS
37 *@@include #include <os2.h>
38 *@@include #include <stdio.h>
39 *@@include #include <setjmp.h>
40 *@@include #include "helpers\except.h"
44 * Copyright (C) 1999-2000 Ulrich M�ller.
46 * 2009-06-15 published under LGPL3 with Ulrich M�ller permission.
54 #ifndef EXCEPT_HEADER_INCLUDED
55 #define EXCEPT_HEADER_INCLUDED
57 #if defined __IBMCPP__ || defined __IBMC__
58 #ifndef INCL_DOSEXCEPTIONS
59 #error except.h requires INCL_DOSEXCEPTIONS to be defined.
61 #ifndef INCL_DOSPROCESS
62 #error except.h requires INCL_DOSPROCESS to be defined.
66 #error except.h requires stdio.h to be included.
69 #error except.h requires setjmp.h to be included.
73 /********************************************************************
77 ********************************************************************/
79 // forward declaration
80 typedef struct _EXCEPTIONREGISTRATIONRECORD2
*PEXCEPTIONREGISTRATIONRECORD2
;
82 // "OnKill" function prototype for EXCEPTIONREGISTRATIONRECORD2
83 // added V0.9.0 (99-10-22) [umoeller]
84 // removed V0.9.7 (2000-12-08) [umoeller]
85 // typedef VOID APIENTRY FNEXCONKILL(PEXCEPTIONREGISTRATIONRECORD2);
86 // typedef FNEXCONKILL *PFNEXCONKILL;
89 *@@ EXCEPTIONREGISTRATIONRECORD2:
90 * replacement EXCEPTIONREGISTRATIONRECORD
91 * struct for thread exception handling.
93 *@@changed V0.9.0 (99-10-22) [umoeller]: pfnOnKill added
94 *@@changed V0.9.0 (99-10-22) [umoeller]: renamed from REGREC2
97 typedef struct _EXCEPTIONREGISTRATIONRECORD2
99 PVOID pNext
; // as in EXCEPTIONREGISTRATIONRECORD
100 PFN pfnHandler
; // as in EXCEPTIONREGISTRATIONRECORD
101 jmp_buf jmpThread
; // additional buffer for setjmp
102 EXCEPTIONREPORTRECORD err
; // exception handlers copy the report rec here
103 PVOID pvUser
; // user ptr
104 } EXCEPTIONREGISTRATIONRECORD2
;
108 * structure used with TRY_xxx macros.
111 typedef struct _EXCEPTSTRUCT
113 EXCEPTIONREGISTRATIONRECORD2 RegRec2
;
114 ULONG ulExcpt
; // != NULL if exception caught
115 APIRET arc
; // rc of DosSetExceptionHandler
116 } EXCEPTSTRUCT
, *PEXCEPTSTRUCT
;
118 // function prototypes for exception hooks (V0.9.0)
120 // "open traplog file" hook
121 typedef FILE* APIENTRY
FNEXCOPENFILE(VOID
);
122 typedef FNEXCOPENFILE
*PFNEXCOPENFILE
;
125 typedef VOID APIENTRY
FNEXCHOOK(FILE*, PTIB
, ULONG
); // V0.9.16 (2001-12-02) [pr]
126 typedef FNEXCHOOK
*PFNEXCHOOK
;
129 typedef VOID APIENTRY
FNEXCHOOKERROR(const char *pcszFile
,
131 const char *pcszFunction
,
133 typedef FNEXCHOOKERROR
*PFNEXCHOOKERROR
;
135 /********************************************************************
139 ********************************************************************/
141 VOID
excExplainException(FILE *file
,
143 PEXCEPTIONREPORTRECORD pReportRec
,
144 PCONTEXTRECORD pContextRec
);
146 VOID
excRegisterHooks(PFNEXCOPENFILE pfnExcOpenFileNew
,
147 PFNEXCHOOK pfnExcHookNew
,
148 PFNEXCHOOKERROR pfnExcHookError
,
149 BOOL fBeepOnExceptionNew
);
151 ULONG _System
excHandlerLoud(PEXCEPTIONREPORTRECORD pReportRec
,
152 PEXCEPTIONREGISTRATIONRECORD2 pRegRec2
,
153 PCONTEXTRECORD pContextRec
,
156 ULONG _System
excHandlerQuiet(PEXCEPTIONREPORTRECORD pReportRec
,
157 PEXCEPTIONREGISTRATIONRECORD2 pRegRec2
,
158 PCONTEXTRECORD pContextRec
,
161 extern PFNEXCHOOKERROR G_pfnExcHookError
;
163 extern ULONG G_ulExplainExceptionRunning
;
165 /********************************************************************
169 ********************************************************************/
171 /* See except.c for explanations how to use these. */
173 #ifdef __NO_EXCEPTION_HANDLERS__
174 // exception handlers can completely be disabled
175 #define TRY_LOUD(excptstruct)
177 #ifdef __NO_LOUD_EXCEPTION_HANDLERS__
178 #define TRY_LOUD(e) TRY_QUIET(e)
179 #else // __NO_LOUD_EXCEPTION_HANDLERS__
180 #define TRY_LOUD(excptstruct) \
182 EXCEPTSTRUCT excptstruct = {0}; \
183 excptstruct.RegRec2.pfnHandler = (PFN)excHandlerLoud; \
184 excptstruct.arc = DosSetExceptionHandler( \
185 (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
186 if (excptstruct.arc) \
187 if (G_pfnExcHookError) \
188 G_pfnExcHookError(__FILE__, __LINE__, __FUNCTION__, excptstruct.arc); \
190 DosBeep(1000, 1000); \
191 excptstruct.ulExcpt = setjmp(excptstruct.RegRec2.jmpThread); \
192 if (excptstruct.ulExcpt == 0) \
195 #endif // __NO_LOUD_EXCEPTION_HANDLERS__
198 #ifdef __NO_EXCEPTION_HANDLERS__
199 // exception handlers can completely be disabled
200 #define TRY_QUIET(excptstruct)
202 #define TRY_QUIET(excptstruct) \
204 EXCEPTSTRUCT excptstruct = {0}; \
205 excptstruct.RegRec2.pfnHandler = (PFN)excHandlerQuiet; \
206 excptstruct.arc = DosSetExceptionHandler( \
207 (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
208 if (excptstruct.arc) \
209 if (G_pfnExcHookError) \
210 G_pfnExcHookError(__FILE__, __LINE__, __FUNCTION__, excptstruct.arc); \
212 DosBeep(1000, 1000); \
213 excptstruct.ulExcpt = setjmp(excptstruct.RegRec2.jmpThread); \
214 if (excptstruct.ulExcpt == 0) \
219 #ifdef __NO_EXCEPTION_HANDLERS__
220 // exception handlers can completely be disabled
221 #define CATCH(excptstruct) if (FALSE) {
223 #define CATCH(excptstruct) \
224 DosUnsetExceptionHandler( \
225 (PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2)); \
226 } /* end of TRY block */ \
228 { /* exception occured: */ \
229 DosUnsetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD)&(excptstruct.RegRec2));
232 #ifdef __NO_EXCEPTION_HANDLERS__
233 // exception handlers can completely be disabled
234 #define END_CATCH() }
236 #define END_CATCH() \
237 } /* end of exception-occured block */ \
243 * this macro is helpful for testing
244 * the exception handlers.
245 * This is not for general use. ;-)
248 #define CRASH {PSZ p = NULL; *p = 'a'; }
250 #endif // EXCEPT_HEADER_INCLUDED