Error Handling

This section contains information about how errors are reported by the IC Imaging Control 4 C Library.

Most library functions return a bool value indicating success or an error status. Functions returning other data types (e.g. const char*) indicate errors by specific values, e.g. NULL. Please refer to the documentation for each function to check the exact way the function reports errors.

If an error occurs, the function stores error information in a thread-local storage. A consecutive successful function call clears the stored error information.

To query the error information after a failed function call, use ic4_get_last_error. The following code snippet shows a function querying the error printing the error message:

void print_last_error()
{
    enum IC4_ERROR code;
    size_t buffer_size = 0;
 
    if (!ic4_get_last_error(&code, NULL, &buffer_size))
    {
        printf("Failed to query error message length\n");
        return;
    }
 
    char* message = malloc(buffer_size);
 
    if (!ic4_get_last_error(&code, message, &buffer_size))
    {
        printf("Failed to query error message\n");
    }
    else
    {
        printf("Error (code %d): %s\n", code, message);
    }
 
    free(message);
}
bool ic4_get_last_error(enum IC4_ERROR *pError, char *message, size_t *message_length)
Query information about the error of the previous library function call.
IC4_ERROR
Contains the possible error codes.
Definition C_Error.h:41