Guidelines for Error Handling

From InterBase

Go Up to Standard Error Handling

The following guidelines apply to all error-handling routines in a program.

Using SQL and Host-language Statements

All SQL statements and InterBase functions can be used in error-handling routines, except for CONNECT.

Any host-language statements and functions can appear in an error-handling routine without restriction.

Use WHENEVER SQLERROR CONTINUE at the start of error-handling routines to disable error-handling temporarily. Otherwise, there is a possibility of an infinite loop; should another error occur in the handler itself, the routine will call itself again.

Nesting Error-handling Routines

Although error-handling routines can be nested or called recursively, this practice is not recommended unless the program preserves the original contents of SQLCODE and the InterBase error status array.

Handling Unexpected and Unrecoverable Errors

Even if an error-handling routine catches and handles recoverable errors, it should always contain statements to handle unexpected or unrecoverable errors.

The following code handles unrecoverable errors:

. . .
isc_print_sqlerr(SQLCODE, isc_status);


For portability among different SQL implementations, SQL programs should limit error handling to WHENEVER statements or direct examination of ­SQLCODE values.

InterBase internal error recognition occurs at a finer level of granularity than SQLCODE representation permits. A single SQLCODE value can represent many different internal InterBase errors. Where portability is not an issue, it may be desirable to perform additional InterBase error handling. The remainder of this chapter explains how to use these additional features.

Advance To: