[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
DosSetExceptionHandler() Install protected mode exception handler
------------------------------------------------------------------------------
Function : Install a protected mode exception handler
Syntax : USHORT BLXAPI DosSetExceptionHandler( USHORT excno, PEHANDLER
newhandler, PEHANDLER _far *prevhandler);
excno Exception number (0-13).
newhandler Pointer to new handler.
prevhandlerPointer to a function pointer to receive the address of the
previous exception handler.
Return : Address of the previous exception handler.
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()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson