The example.c program includes the header file example.h for error handling of XDS and XOM function calls. The example.h program contains two error handling functions: CHECK_DS_CALL for handling XDS API errors, and CHECK_OM_CALL for handling XOM API errors. Note that CHECK_DS_CALL and CHECK_OM_CALL are created specifically for example.c and are not part of the XDS or XOM APIs. They are included to demonstrate a possible method for error handling.
XDS and XOM API functions return a status code. In example.c, error contains the status code for XDS API functions. If the call is successful, the function returns DS_SUCCESS. Otherwise, one of the error codes described in XDS Class Definitions is returned.
The return_code variable contains the status code for XOM API functions. If the call is successful, the function returns OM_SUCCESS. Otherwise, one of the error codes described in XOM Service Interface is returned.
The contents of example.h are as follows:
/*
* define some convenient exit codes
*/
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
/*
* declare an error handling function and
* an error checking macro for DS
*/
void handle_ds_error(DS_status error);
#define CHECK_DS_CALL(function_call)
error = (function_call);
if (error != DS_SUCCESS)
handle_ds_error(error);
/*
* declare an error handling function and
* an error checking macro for OM
*/
void handle_om_error(OM_return_code return_code);
#define CHECK_OM_CALL(function_call)
return_code = (function_call);
if (return_code != OM_SUCCESS)
handle_om_error(return_code);
/*
* the error handling code
*
* NOTE: any errors arising in these functions are ignored.
*/
void handle_ds_error(DS_status error)
{
(void) fprintf(stderr, "DS error has occurred\n");
(void) om_delete((OM_object) error);
/* At this point, the error has been reported and storage cleaned up,
* so the handler could return to the main program now for it to take
* recovery action. But we choose the simple option ...
*/
exit(EXIT_FAILURE);
}
void handle_om_error(OM_return_code return_code)
{
(void) fprintf(stderr, "OM error %d has occurred\n", return_code);
/* At this point, the error has been reported and storage cleaned up,
* so the handler could return to the main program now for it to take
* recovery action. But we choose the simple option ...
*/
exit(EXIT_FAILURE);
}