Manage errors
Most operations, such as issuing queries, fetching rows, and setting
transaction states, return a result code that your application checks.
Operations that return pointers typically return NULL
to
indicate an error. Operations that return a Boolean result typically
return FALSE
to indicate an error.
To specify a routine to be called whenever an error or warning is posted, your application can associate a callback function with an instance of these classes. If an error occurs, the callback function is executed. See The ITErrorManager class for the callback function signature.
To check errors from operation objects, call the Error and ErrorText methods after an operation is performed, or include calls to the Error and ErrorText methods in the body of an error callback function added to the object. Within an error callback function, the only safe operations are calls to the Error, ErrorText, Warn, WarningText, and SqlState methods to examine the ErrorManager object.
Your own data structures can be accessed with the user data parameter, which is untouched by the . Any operations in the callback function that are performed by using the Object Interface for C++, such as calls to the operation class methods that submit queries, have undefined results.
The ITErrorManager base class gives its derived classes the ability to manage errors returned by the server or generated within the Object Interface for C++.
Callbacks added to an operation class derived from ITErrorManager are added to that interface object. If the interface object is deleted, the callbacks registered on that interface are removed. If the interface object is deleted while the implementation is still present and the callbacks were not removed, there is no valid interface object reference for the first parameter of the callback when the implementation calls the callback, and a segmentation violation might occur. The destructor of ITErrorManager removes such a callback.
To track all errors on a connection, set a callback function on the connection object. When processing errors from a connection object, be sure to check the return status from the operation itself, and not from the Error method. To track all errors for a specific object, set a callback function on the object itself.