Borland C++ reference

harderr, hardresume, hardretn

raw OCR

Establishes and handles hardware errors.

Defined in header <dos.h>

Syntax

#include <dos.h>
void harderr(int {*handler)0);
void hardresume(int  axret);
void hardretn(int retn);

Portability

DOSUNIXWindowsANSI CC++ only
■

Remarks

The error handler established by harderr can call hardresume to return to DOS. The return value of the rescode (result code) of hardresume contains an abort (2), retry (1), or ignore (0) indicator. The abort is accomplished by invoking DOS interrupt 0x23, the control-break interrupt.

The error handler established by harderr can return directly to the application program by calling hardretn. The returned value is whatever value you passed to hardretn.

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:

handler(int errval, int ax, int bp, int si);

errval is the error code set in the DI register by DOS. ax, bp, and si are the values DOS sets for the AX, BP, and SI registers, respectively.

■ ax indicates whether a disk error or other device error was encountered. If ax is nonnegative, a disk error was encountered; otherwise, the error was a device error. For a disk error, ax ANDed with OxOOFF gives the failing drive number (0 equals A, 1 equals B, and so on). ■ hp and si together point to the device driver header of the failing driver. hp contains the segment address, and si the offset.

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 must return 0 for ignore, 1 for retry, and 2 for abort.

Return value

None.

See also

Example

/* This program will  trap disk errors and prompt the user for action. Try  running
   it with no disk  in drive A: to invoke its functions.
V
#include <stdio.h>
#include <conio.h>
#include <dos.h>

Mefine  IGNORE   0
#define RETRY   1
#define ABORT   2

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  (ORG)",
    "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"
};
error_win(char *msg)

   int retval;
   cputs(msg);
/* Prompt for user to press  a key to abort, retry, ignore. */
   while(l) {
      retval= getchO  ;
      if  (retval == 'a' II retval == 'A') {
          retval  = ABORT;
          break;
      }
   if  (retval == 'r' || retval == 'R') {
       retval = RETRY;
       break;
   }
   if  (retval == 'i' II retval == 'I')
   {
       retval = IGNORE;
       break;

   return (retval);
}

/*
pragma warn -par reduces warnings  which occur
due to the non use of the parameters  errval,
bp and si to the handler.
*/
#pragma warn -par
int handler (int errval,int ax,int bp,int si)
{
   static char msg[80] ;
   unsigned di;
   int drive;
   int errorno;
   di= _DI;
I*
if this is not a disk error  then it was
another device having trouble
*/
   if (ax < 0)
   {
      /* report the error  */
      error_win( "Device error");
      /* and return to the program  directly requesting abort */
      hardretn (ABORT);
   }
/* otherwise it was a disk  error */
   drive = ax & OxOOFF;
   errorno = di & OxOOFF;
/* report which error it was  */
   sprintf (msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore:
       err_msg[errorno] , 'A' + drive);
/*
return to the program via dos  interrupt 0x23 with abort, retry,
or ignore as input by the user.
V
   hardresume (error_win(msg));
   return ABORT;
}
ttpragma warn +par
int main (void)
{
/*

install our handler on the hardware  problem interrupt
V
   harderr (handler);
   clrscrO ;
   printfC'Make sure there  is no disk in drive A:\n");
   printf ("Press any key ....\n");
   getchO ;
   printf ("Trying to access drive A:\n");
   printf ("fopen returned %p\n",fopen("A:temp.dat", "w"));
   return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.