An application can handle CS-Library messages in one of two ways:
By installing a callback routine to handle messages
Inline, using the CS-Library routine cs_diag
The callback method has the advantages of:
Gracefully handling unexpected errors
CS-Library automatically calls the appropriate message callback routine whenever a message is generated, so an application will not fail to trap unexpected errors. An application using only inline error-handling logic may not successfully trap errors that have not been anticipated.
Centralizing message-handling code
Since all errors are handled in the callback, there is no need to add inline message-handling code after each CS-Library call.
Inline message handling has the advantage of allowing an application to check for messages at particular times. For example, an application that makes a sequence of calls to establish a connection might wait until the connection-related call sequence is complete before checking for messages.
Most applications use the callback method to handle messages.
An application indicates which method it will use for a particular context either by calling cs_config to install a message callback routine or by calling cs_diag to initialize inline message handling.
An application can switch back and forth between the inline method and the callback method:
Installing a message callback routine turns off inline message handling. Any saved messages are discarded.
Likewise, calling cs_diag to initialize inline message handling “de-installs” the application’s CS-Library message callback. As a result, the application’s first CS_GET call to cs_diag will retrieve a warning message to this effect.
If a message callback is not installed and inline message handling is not enabled, CS-Library discards message information.