_harderr
Establishes a hardware error handler.
Defined in header <dos.h>
Syntax
#include <dos.h>
void _harderr(int (far *handler)0)',
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ |
Remarks
_harderr establishes a hardware error handler for the current program. This error handler is invoked whenever an interrupt 0x24 occurs. (See your DOS reference manuals for a discussion of the interrupt.)
The function pointed to by handler is called when such an interrupt occurs. The handler function is called with the following arguments:
void far handler(unsigned deverr, unsigned errval, unsigned far *devhdr);
B deverr is the device error code (passed to the handler by DOS in the AX register). ■ errval is the error code (passed to the handler by DOS in the DI register).
■ devhdr a far pointer to the driver header of the device that caused the error (passed to the handler by DOS in the BP:SI register pair).
The handler should use these arguments instead of referring directly to the CPU registers.
deverr indicates whether a disk error or other device error was encountered. If bit 15 of deverr is 0, a disk error was encountered. Otherwise, the error was a device error. For a disk error, deverr ANDed with OxOOFF give the failing drive number (0 equals A, 1 equals B, and so on).
The function pointed to by handler is not called directly. _harderr establishes a DOS interrupt handler that calls the function.
The handler can issue DOS calls 1 through 0xC; any other DOS call corrupts DOS. In particular, any of the C standard I/O or UNIX-emulation I/O calls cannot be used.
The handler does not return a value, and it must exit using _hardretn or _hardresume.
Return value
None.
See also
Example
/* This program traps disk errors and prompts the user for action. */
/* Try running it v/ith no disk in drive A to invoke its functions. */
#include <stdio.h>
#include <ctype.h>
*include <dos.h>
#include <fcntl.h>
int buf[500];
/* Define the error messages for trapping disk problems. */
static char *err_msg[] =
{
"write protect", "unknown unit",
"drive not ready", "unknown command",
"data error (CRC)","bad request",
"seek error", "unknown media type",
"sector not found","printer out of paper",
"write fault", "read fault",
"general failure", "reserved",
"reserved", "invalid disk change"
}; '
static void mesg(char *s)
while (*s)
bdos(2,*s++,0);
}
static int getkey{void)
{
return (bdos(7, 0, 0) & 0xff);
]
error_win(char *msg)
{
int c;
/* Prompt user to press a key to abort, retry, ignore, fail. */
while (1) {
mesglmsg);
c = tolower (getkey0 );
mesg("\r\n" );
switch (c) {
case 'a':
return (_HARDERR_ABORT);
case 'r':
return (_HARDERR_RETRY);
case 'i':
return (_HARDERR_IGNORE);
case 'f :
return (_HARDERR_FAIL);
}
}
}
/* Pragma warn -par reduces warnings which occur due to the nonuse of the
parameter devhdr */
ipragma warn -par
void far handler (unsigned deverr, unsigned errval,
unsigned far *devhdr)
{
static char msg[80];
int drive, errorno;
/* If this not disk error then another device having trouble. */
if (deverr & 0x8000) {
error_win("Device error"); /* report the error */
/* return to the program directly requesting abort */
_hardretn(5); /* 5 = DOS "access denied" error */
}
drive = deverr & OxOOFF; /* otherwise it was disk error */
errorno = errval & OxOOFF;
/* report which error it was */
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry,
I)gnore, F)ail: ",
err_msg[errorno], 'A' + drive);
/* Return to program via dos interrupt 0x23 with abort, retry or ignore as
input by the user */
_hardresume(error_win(msg));
}
#pragma warn +par
int main(void)
{
int handle;
/* Install our handler on the hardware problem interrupt. */
_harderr(handler);
printfC'Make sure there is no disk in drive A:\n");
printf("Press any key ...An");
get key 0;
printf("Trying to access drive A:\n");
printf("_dos_open returned Ox%x\n",
_dos_open("A:temp.dat", 0_RDONLY, &handle));
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Extraction notes
- heading `harderr` read as `_harderr`
Stable link: /3.1/dos.h/_harderr/
· short form /3.1/_harderr/