Imaging Control 4 C++ Library 1.2.0
|
This section contains information about how errors are reported by the IC Imaging Control 4 C++ Library.
Most library functions have an output parameter Error& err
. If an error occurs, the error code and error message are passed to the error handler object referenced by err
.
The err
parameter is defaulted to ic4::Error::Default, which by default ignores alls errors.
Using any library function or class without calling ic4::initLibrary() first always throws an exception with the error code set to ic4::ErrorCode::LibraryNotInitialized.
To capture the error information for a library function call, create a local ic4::Error object and pass it to the function being called. If the function indicates an error (for example by returning false
), check the error message:
Exceptions can be enabled globally or on a per-function basis.
To enable exceptions for all function calls, pass ic4::ErrorHandlerBehavior::Throw to ic4::initLibrary. This configures ic4::Error::Default() to throw exceptions:
With exceptions enabled globally, it is still possible to capture the error of specific function calls into a local error variable. In this case, no exception is thrown:
If error information is not required for a specific function call, it is possible to ignore an error entirely.
Ignoring errors is generally only recommended when performing optional operations, such as initializing properties that are not necessarily present in all devices.
To enable exceptions for errors from a specific function call, pass ic4::Error::Throw() to its err
argument: