DB-Library/C applications must handle two types of messages and errors:
Server messages and errors, which range in severity from informational messages to fatal errors. Server messages and errors are known to DB-Library/C applications as “messages.” To list all possible Adaptive Server Enterprise messages, use the Transact-SQL command:
select * from sysmessages
For a list of Adaptive Server Enterprise messages, see the Adaptive Server Enterprise System Administration Guide. For a list of Open Server messages, see the Open Server Server-Library/C Reference Manual.
DB-Library/C warnings and errors, known to DB-Library/C applications as “errors.” For a list of DB-Library/C errors, see Errors.
Also, success or failure indications are returned by most DB-Library/C routines.
To handle server messages, DB-Library/C errors, and success or failure indications, a DB-Library/C application can:
Test DB-Library/C routine return codes in the mainline code, handling failures on a case-by-case basis.
Centralize message and error handling by installing a message handler and an error handler, which are then automatically called by DB-Library/C when a message or error occurs.
Sybase strongly recommends that all DB-Library/C applications use centralized message and error handling in addition to mainline error testing. Centralized message and error handling has substantial benefits for large or complex applications. For example:
Centralized message and error handling reduces the need for mainline error-handling logic. This is because DB-Library/C calls an application’s message and error handlers automatically whenever a message or error occurs.
Note, however, that even an application that uses centralized error and message handling will need some mainline error logic, depending on the nature of the application.
Centralized message and error handling provides a mechanism for gracefully handling unexpected errors. An application using only mainline error-handling logic may not successfully trap errors which have not been anticipated.
To provide a DB-Library/C application with centralized message and error handling, the application programmer must write a message handler and an error handler and install them using dbmsghandle and dberrhandle.
The DB-Library/C routines for message and error handling are:
dbmsghandle – installs a user function to handle server informational and error messages.
dberrhandle – installs a user function to handle DB-Library/C error messages.
DBDEAD – determines whether a particular DBPROCESS is dead. When a DBPROCESS is dead, the current DB-Library/C routine fails, causing the error handler to be called.