AerospikeC client manual --- error handling
For error handling, each database operation accepts an as_error object as a parameter. When an error occurs during the operation, the as_error parameter is filled in with the status code and error message. Generally, the as_error parameter is the second parameter for database operations.
As_error provides the following information:
Code-operation status. The type is as_status.
Message-information of the error code. If the operation is completed successfully, this information may be NULL ).
Func-name of the function in which the error occurs. If the capture fails, it may be NULL ).
File-the name of the file where the error occurs. If the capture fails, it may be NULL ).
Line-the row number of the file where the error occurs. If the capture fails, it may be 0.
After the operation is complete, a value of the as_status type is returned, which corresponds to as_error.code. If the operation returns a failure state, it is generally not AEROSPIKE_ OK. The application should check the as_error variable for more information. For more information, see as_status.h.
An as_error variable can be reused for multiple operations. Each operation resets as_error and sets a value when an error occurs.
The following is a simple example of error handling:
If (aerospike_key_put (& as, & err, NULL, & key, & rec )! = AEROSPIKE_ OK) {fprintf (stderr, "err (% d) % s at [% s: % d] \ n", err. code, err. message, err. file, err. line );}