2.3 Error Handling

All driver functions provide a basic error trapping mechanism that stores the last reported error in the driver. If your application is not behaving properly, you can check for the last error by calling the function dscGetLastError. This function takes an ERRPARAMS structure pointer as its argument.

Nearly all of the available functions in the UD API return a BYTE value upon completion. This value represents an error code that will inform you as to whether or not the function call was successful. You should always check if the result returns a DE_NONE value (signifying that no errors were reported), as the code below illustrates:

BYTE result;
ERRPARAMS errparams;

if ((result = dscInit(DSC_VERSION)) != DE_NONE)
{
    dscGetLastError(&errparams);
    fprintf(stderr, "dscInit failed: %s (%s)\n", dscGetErrorString(result), errparams.errstring);
    return result;
}

In this code snippet, the BYTE result of executing a particular driver function (dscInit in this case) is stored and checked against the expected return value (DE_NONE). Anytime a function does not complete successfully, an error code other than DE_NONE will be generated, and the current API function will terminate. The function dscGetErrorString provides a description of the error that occurred.

Last updated