dberrhandle

Description

Install a user function to handle DB-Library errors.

Syntax

int (*dberrhandle(handler))()
 
int          (*handler)();

Parameters

handler

A pointer to the user function that will be called whenever DB-Library determines that an error has occurred. DB-Library calls this function with six parameters shown in Table 2-17.

Table 2-17: Error handler parameters

Parameter

Meaning

dbproc

The affected DBPROCESS. If there is no DBPROCESS associated with this error, this parameter will be NULL.

severity

The severity of the error (datatype int). Error severities are defined in syberror.h.

dberr

The identifying number of the error (datatype int). Error numbers are defined in sybdb.h.

oserr

The operating-system-specific error number that describes the cause of the error (datatype int). If there is no relevant operating system error, the value of this parameter will be DBNOERR.

dberrstr

A printable description of dberr (datatype char *).

oserrstr

A printable description of oserr (datatype char *).

The error handler must return one of the four values listed in Table 2-18, directing DB-Library to perform particular actions:

Table 2-18: Error handler returns

Return

Action

INT_EXIT

Print an error message and abort the program. DB-Library will also return an error indication to the operating system. (Note to UNIX programmers: DB-Library will not leave a core file.

INT_CANCEL

Return FAIL from the DB-Library routine that caused the error. Returning INT_CANCEL on timeout errors will kill the dbproc.

INT_TIMEOUT

Cancel the operation that caused the error but leave the dbproc in working condition. This return value is meaningful only for timeout errors (SYBETIME). In any other case, this value will be considered an error, and will be treated as an INT_EXIT.

INT_CONTINUE

Continue to wait for one additional timeout period. At the end of that period, call the error handler again. This return value is meaningful only for timeout errors (SYBETIME). In any other case, this value will be considered an error, and will be treated as an INT_EXIT.

If the error handler returns any value besides these four, the program will abort.

Error handlers on the Microsoft Windows platform must be declared with CS_PUBLIC, as shown in the example below. For portability, callback handlers on other platforms should be declared CS_PUBLIC as well.

The following example shows a typical error handler routine:

#include   <sybfront.h> 
#include  <sybdb.h> 
#include  <syberror.h> 
int CS_PUBLIC err_handler(dbproc, severity, dberr,
oserr, dberrstr, oserrstr)
DBPROCESS    *dbproc; 
 int          severity; 
 int          dberr; 
 int          oserr; 
 char         *dberrstr; 
 char         *oserrstr; 
{ 
      if ((dbproc == NULL) || (DBDEAD(dbproc))) 
           return(INT_EXIT); 
      else  
      { 
           printf("DB-Library error:\n\t%s\n",
                dberrstr); 
           if (oserr != DBNOERR) 
                printf("Operating-system \
                     error:\n\t%s\n", oserrstr); 
           return(INT_CANCEL); 
      } 
 } 

Returns

A pointer to the previously installed error handler. This pointer is NULL if no error handler was installed before.

Usage

See also

DBDEAD, dbmsghandle, Errors