|
Most API routines return a record of type
outcome. For example:
|
|
|
outcome api_make_cuboid(...)
|
|
|
An
outcome holds an error number of type
err_mess_type, which is an integer. If the
outcome is successful, the error number is 0. A calling function may examine the
outcome using the following functions:
|
|
|
ok
|
Returns
TRUE if the
outcome was successful, (the error number is 0).
|
|
|
error_number
|
Returns the error number.
|
|
|
find_err_mess
|
Returns the text for the error message.
|
|
|
Example 8-4 illustrates an API function call.
|
|
|
C++ Example
|
|
|
outcome result = api_make_cuboid(width, depth, height, body);
|
|
if(! result.ok())
|
|
{
|
|
err_mess_type err_no = result.error_number();
|
|
printf("Error in make_cuboid %d : %s\n",
|
|
|
err_no, find_err_mess(err_no));
|
|
}
|
|
|
Example 8-4. Example API Call
|
|
|
Every API routine includes an error trap to catch error exits from within the modeler.
|
|
|
The API routine may detect some warning conditions that do not cause the operation to exit. The warning messages are not returned with the
outcome. Rather, the application must ask the error system for a list of the warnings caused.
|
|
|
Example 8-5 shows how to print warning messages.
|
|
|
C++ Example
|
|
|
err_mess_type* warnings;
|
|
int nwarn = get_warnings(warnings);
|
|
for (int i = 0; i < nwarn; ++i) {
|
|
printf("Warning %d : %s\n",
|
|
|
warnings[i],
|
|
|
find_err_mess(warnings[i]));
|
|
}
|
|
|
Example 8-5. Example Warning Message Handling
|
|
|
If logging for roll back is in operation, an error in an API routine causes the model to be rolled back to its state prior to the call. If logging is off, the modeler halts.
|