| 1 |  | 
|---|
| 2 | #ifndef EXCEPT_H_INCLUDED | 
|---|
| 3 | #define EXCEPT_H_INCLUDED | 
|---|
| 4 |  | 
|---|
| 5 | #include <setjmp.h> | 
|---|
| 6 | #include "excptLogName.h" | 
|---|
| 7 |  | 
|---|
| 8 | typedef struct REGREC2_STRUCT { | 
|---|
| 9 | PVOID     pNext; | 
|---|
| 10 | PFN       pfnHandler; | 
|---|
| 11 | jmp_buf   jmpThread; | 
|---|
| 12 | } REGREC2, *PREGREC2; | 
|---|
| 13 |  | 
|---|
| 14 | typedef struct _LOCALEXCEPTSTRUCT { | 
|---|
| 15 | //REGREC2               RegRec2; | 
|---|
| 16 | EXCEPTIONREGISTRATIONRECORD  excptRegRecord; | 
|---|
| 17 | ULONG                 ulExcpt; | 
|---|
| 18 | APIRET                arc; | 
|---|
| 19 | jmp_buf   jmpThread; | 
|---|
| 20 | } LOCALEXCEPTSTRUCT, *PLOCALEXCEPTSTRUCT; | 
|---|
| 21 |  | 
|---|
| 22 | /******************************************************************** | 
|---|
| 23 | *                                                                  * | 
|---|
| 24 | *   Macros                                                         * | 
|---|
| 25 | *                                                                  * | 
|---|
| 26 | ********************************************************************/ | 
|---|
| 27 |  | 
|---|
| 28 | /* See except.c for explanations how to use these. */ | 
|---|
| 29 |  | 
|---|
| 30 | #define TRY_LOUD(localExceptStruct)                                   \ | 
|---|
| 31 | {  \ | 
|---|
| 32 | LOCALEXCEPTSTRUCT    localExceptStruct;                         \ | 
|---|
| 33 | localExceptStruct.excptRegRecord.ExceptionHandler = (ERR)excHandler;          \ | 
|---|
| 34 | localExceptStruct.arc = DosSetExceptionHandler(                  \ | 
|---|
| 35 | (PEXCEPTIONREGISTRATIONRECORD)&(localExceptStruct.excptRegRecord)); \ | 
|---|
| 36 | if (localExceptStruct.arc)                                       \ | 
|---|
| 37 | DosBeep(100, 1000);                                    \ | 
|---|
| 38 | localExceptStruct.ulExcpt = setjmp(localExceptStruct.jmpThread);               \ | 
|---|
| 39 | if (localExceptStruct.ulExcpt == 0)                              \ | 
|---|
| 40 | {   /* no exception occured: */ | 
|---|
| 41 |  | 
|---|
| 42 | #define CATCH(localExceptStruct)                                       \ | 
|---|
| 43 | DosUnsetExceptionHandler(                              \ | 
|---|
| 44 | (PEXCEPTIONREGISTRATIONRECORD)&(localExceptStruct.excptRegRecord));   \ | 
|---|
| 45 | } /* end if (try_ulExcpt == 0) */                          \ | 
|---|
| 46 | else { /* exception occured: */                            \ | 
|---|
| 47 | DosUnsetExceptionHandler(                              \ | 
|---|
| 48 | (PEXCEPTIONREGISTRATIONRECORD)&(localExceptStruct.excptRegRecord)); | 
|---|
| 49 | #define END_CATCH                                                      \ | 
|---|
| 50 | } /* end else (excptstruct.ulExcpt == 0) */                \ | 
|---|
| 51 | } /* end variable scope block */ | 
|---|
| 52 |  | 
|---|
| 53 |  | 
|---|
| 54 | /* | 
|---|
| 55 | * CRASH: | 
|---|
| 56 | *      this macro is helpful for testing | 
|---|
| 57 | *      the exception handlers. | 
|---|
| 58 | *      This is not for general use. ;-) | 
|---|
| 59 | */ | 
|---|
| 60 |  | 
|---|
| 61 | #define CRASH {PSZ p = NULL; *p = 'a'; } | 
|---|
| 62 |  | 
|---|
| 63 | /******************************************************************** | 
|---|
| 64 | *                                                                  * | 
|---|
| 65 | *   Prototypes                                                     * | 
|---|
| 66 | *                                                                  * | 
|---|
| 67 | ********************************************************************/ | 
|---|
| 68 |  | 
|---|
| 69 | ULONG _System excHandler(PEXCEPTIONREPORTRECORD pERepRec, | 
|---|
| 70 | PLOCALEXCEPTSTRUCT pRegRec2, | 
|---|
| 71 | //          PREGREC2 pRegRec2, | 
|---|
| 72 | PCONTEXTRECORD pCtxRec, | 
|---|
| 73 | PVOID pv); | 
|---|
| 74 | #if 0 | 
|---|
| 75 | ULONG _System excHandler(PEXCEPTIONREPORTRECORD pReportRec, | 
|---|
| 76 | PREGREC2 pRegRec2, | 
|---|
| 77 | PCONTEXTRECORD pContextRec, | 
|---|
| 78 | PVOID pv); | 
|---|
| 79 | #endif | 
|---|
| 80 | #endif | 
|---|