Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Blinker 5.10 Online Reference - <b> dossetexceptionhandler()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 DosSetExceptionHandler()
------------------------------------------------------------------------------
 Purpose:
 Install a protected mode exception handler.

 Syntax:
 USHORT BLXAPI DosSetExceptionHandler(USHORT excno,
                   PEXCHAN newhandler,
                   PEXCHAN __far *prevhandler);

 Parameters:
 excno        Exception number (0-13).
 newhandler   Pointer to new handler.
 prevhandler  Pointer to a function pointer to receive the address of the
              previous exception handler.

 Returns:
 Address of the previous exception handler.

 Description:
 DosSetExceptionHandler() installs a protected mode handler for processor
 exceptions.

 The exceptions it is possible to handle are:
 0x00  Divide by zero
 0x01  Debug
 0x03  Breakpoint
 0x04  Overflow
 0x05  Bounds check
 0x06  Invalid opcode
 0x07  287/387 not available
 0x08  Double fault
 0x0A  Invalid task switch segment
 0x0B  Segment not present
 0x0C  Stack fault
 0x0D  General protection fault

 Example:
 #include <stdio.h>                                                          
 #include <stdlib.h>                                                         
 #include <blx286.h>                                                         
                                                                             
 PEXCHAN prevhandler;                                                        
                                                                             
 void printstr (char *s)    /* Cannot use C screen i/o */                    
    {                                                                        
    char c;                                                                  
    while (c = *(s++))         /* Until end of string */                     
       {                                                                     
       _asm mov ah,0eh                                                       
       _asm mov al,c                                                         
       _asm int 10h         /* Display teletype */                           
       }                                                                     
    }                                                                        
 void _interrupt far gphandler(EXCEP_FRAME ef)                               
    {                                                                        
    char msg [80];                                                           
    printstr ("Replacement GPF handler\n\r");                                
    printstr ("-----------------------\n\r");                                
    sprintf (msg,"Error code = %04x\n\r",ef.error_code);                     
    printstr (msg);                                                          
    sprintf (msg," CS:IP = %04x:%04x\n\r", ef.ret_cs, ef.ret_ip);            
    printstr (msg);                                                          
    DosSetExceptionHandler (0x0d,prevhandler,NULL);                          
    exit (255);                                                              
 }                                                                           
 void main (void)                                                            
 {                                                                           
 PEXCHAN newhandler;                                                         
                                                                             
 newhandler = gphandler;                                                     
 if (DosSetExceptionHandler (0x0d, newhandler,&prevhandler) == 0)            
    {                                                                        
    *((USHORT far *) 0x22222222L) = 1;     /* Cause exception                
 */                                                                          
    printf("Somehow no exception occurred\n");                               
    DosSetExceptionHandler (0x0d,prevhandler,NULL);                          
    }                                                                        
 }                                                                           

See Also: DosGetExceptionHandler()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson