The DataBlade API throws the MI_Client_Library_Error event to indicate an error in the client LIBMI library. The MI_Client_Library_Error event indicates the type of error that has occurred with one of the error levels that Table 72 shows.
To handle an MI_Client_Library_Error event, you can write either of the following types of callback function:
Use the mi_register_callback( ) function to register callback functions. After you register a callback that handles the MI_Client_Library_Error event, the client LIBMI invokes this callback instead of performing its default error handling.
Write a callback that handles MI_Client_Library_Error when you need to provide special handling for one or more client LIBMI errors, which Table 72 shows. Within the callback, the mi_error_level( ) function returns the error level for the client LIBMI error. You can also use the following DataBlade API functions to get more details about the client LIBMI error from its error descriptor:
For more information, see Accessing an Error Descriptor.
The following sample code uses special-purpose handlers (not shown) to handle messages (message_handler( )) and database server exceptions (exception_handler( )). The message_handler( ) routine might simply display a message on standard error, while the other handlers could take some specific user-defined action based on the type of exception.
/* This routine dispatches callback events for the following * events: * MI_Exception (client-side & server-side), * MI_Client_Library_Error (client-side only) * MI_Xact_State_Change (client-side only) */ #include "mi.h" MI_CALLBACK_STATUS MI_PROC_CALLBACK all_callback(event_type, conn, event_data, user_data) MI_EVENT_TYPE event_type; MI_CONNECTION *conn; void *event_data; void *user_data; { mi_integer elevel; char err_msg[200]; char *msg; switch ( event_type ) { /* A database server exception calls a special-purpose ** handler to handle a message (warning) or an ** exception. */ case MI_Exception: /* Obtain exception level from event */ elevel = mi_error_level(event_data); switch ( elevel ) { case MI_MESSAGE: message_handler(event_data, user_data); break; case MI_EXCEPTION: exception_handler(event_data, user_data); break; } break; /* A client LIBMI error is any type of internal ** client-library error, library-usage problem, or ** a dropped connection. */ case MI_Client_Library_Error: /* Obtain error level from event */ elevel = mi_error_level(event_data); switch ( elevel ) { case MI_LIB_BADARG: msg = "MI_LIB_BADARG"; break; case MI_LIB_USAGE: msg = "MI_LIB_USAGE"; break; case MI_LIB_INTERR: msg = "MI_LIB_INTERR"; break; case MI_LIB_NOIMP: msg = "MI_LIB_NOIMP"; break; case MI_LIB_DROPCONN: msg = "MI_LIB_DROPCONN"; break; default: msg = "UNKNOWN"; break; } mi_errmsg(event_data, err_msg, 200); fprintf(stderr, "%s: %s\n", msg, err_msg); break; /* A transaction-state-change event occurs whenever ** the client LIBMI module begins or ends a ** transaction block. */ case MI_Xact_State_Change: { mi_integer change_type; /* Obtain transition type from event */ change_type = mi_transition_type(event_data); switch ( change_type ) { case MI_BEGIN: msg = "Transaction started."; break; case MI_NORMAL_END: msg = "Transaction committed."; break; case MI_ABORT_END: msg = "Transaction aborted!"; break; default: msg = "Unknown transaction type!"; break; } fprintf(stderr, "%s\n", msg); break; } /* No other types of events are expected here, * although they could happen. Let the user know * what happened and continue. */ default: fprintf(stderr, "Caught an unexpected event type.\n"); break; } return MI_CB_CONTINUE; }
The all_callback( ) callback returns a status of MI_CB_CONTINUE when it is invoked from a C UDR. Therefore, the database server would check for additional callbacks that are registered for the event once it completed execution of all_callback( ). If no additional callbacks existed, the database server would abort the UDR.