DosSetExceptionHandler

Registers an exception handler for the current thread.

Syntax
DosSetExceptionHandler (pERegRec)

Parameters
This exception registration record must be on the stack.
 * pERegRec (PEXCEPTIONREGISTRATIONRECORD) - input : A pointer to the exception registration record that describes the exception handler to be registered.

Return Code
ulrc (APIRET) - returns DosSetExceptionHandler returns one of the following value:
 * 0 NO_ERROR

Remarks
Note: Do not make Presentation Manager calls from exception handlers.

DosSetExceptionHandler registers an exception handler for the current thread.

If you register more than one exception handler within the same procedure, each handler's exception registration record must have a lower storage address (a higher position on the stack) than the exception registration record of the previously installed handler.

For a detailed list of the system exceptions, see System Exceptions.

Example Code
This example shows how to set an exception handler for the current thread. 
 * 1) define INCL_DOSPROCESS      /* DOS process values (for DosSleep) */
 * 2) define INCL_DOSEXCEPTIONS   /* DOS exception values */
 * 3) define INCL_ERRORS          /* DOS error values     */
 * 4) include 
 * 5) include 

ULONG _System MyTermHandler( PEXCEPTIONREPORTRECORD      p1,                             PEXCEPTIONREGISTRATIONRECORD p2,                             PCONTEXTRECORD               p3,                             PVOID                        pv );

int main (VOID) { EXCEPTIONREGISTRATIONRECORD RegRec  = {0};     /* Exception Registration Record */ APIRET     rc      = NO_ERROR;   /* Return code                   */

/* Add MyTermHandler to this thread's chain of exception handlers */

RegRec.ExceptionHandler = (ERR)MyTermHandler; rc = DosSetExceptionHandler( &RegRec ); if (rc != NO_ERROR) { printf("DosSetExceptionHandler error: return code = %u\n",rc); return 1; }

printf("Terminate this program using Ctrl-C or Ctrl-Break.\n");

rc = DosSleep(60000L);  /* Give user plenty of time to comply... */

rc = DosUnsetExceptionHandler( &RegRec ); if (rc != NO_ERROR) { printf("DosUnsetExceptionHandler error: return code = %u\n",rc); return 1; } return NO_ERROR; } /***************************************************************************/ ULONG _System MyTermHandler( PEXCEPTIONREPORTRECORD      p1,                             PEXCEPTIONREGISTRATIONRECORD p2,                             PCONTEXTRECORD               p3,                             PVOID                        pv ) { printf("*** MyTermHandler entered: ExceptionNum = %x\n",p1->ExceptionNum); switch( p1->ExceptionNum) { case XCPT_SIGNAL: { printf(" XCPT_SIGNAL"); switch( p1->ExceptionInfo[0] ) { case XCPT_SIGNAL_INTR:    { printf("_INTR"); break; } case XCPT_SIGNAL_KILLPROC: { printf("_KILLPROC"); break; } case XCPT_SIGNAL_BREAK:   { printf("_BREAK"); break; } default:; }     printf("\n"); break; }  case XCPT_PROCESS_TERMINATE:       { printf(" Process Terminate \n"); break;} case XCPT_ASYNC_PROCESS_TERMINATE: { printf(" Async Process Term\n"); break;} case XCPT_UNWIND:                 { printf(" XCPT_UNWIND\n");        break;} default:; }

return XCPT_CONTINUE_SEARCH;         /* Exception not resolved... */ } 

Related Functions

 * DosAcknowledgeSignalException
 * DosEnterMustComplete
 * DosExitMustComplete
 * DosRaiseException
 * DosSendSignalException
 * DosSetSignalExceptionFocus
 * DosUnsetExceptionHandler
 * DosUnwindException