Name

lcb_set_error_callback — Set callback for error

Synopsis

cc [ flag … ] file… -lcouchbase [ library … ]

#include <libcouchbase/couchbase.h>
lcb_error_callback lcb_set_error_callback(lcb_t instance, lcb_error_callback callback);

DESCRIPTION

lcb_set_error_callback() is used to set a new callback function to handle error situations a given libcouchbase instance.

Please note that the command callbacks will be called for each command specified, and the error callback is called for errors without a command context. The error callback function has the following prototype:

void function(lcb_t instance,
              lcb_error_t error,
              const char * errinfo);

instance is the libcouchbase instance with the error, error is the error code and errinfo contains a more information (if non-null).

RETURN VALUES

lcb_set_error_callback() returns the previous callback function.

EXAMPLES

Example 1: Query the current callback

#include <libcouchbase/couchbase.h>
...
lcb_t instance;
...
lcb_error_callback old;
old = lcb_set_error_callback(instance, NULL);
...

Example 2: Install custom callback

#include <libcouchbase/couchbase.h>
...
static void callback(lcb_t instance, lcb_error_t error,
                     const char *errinfo)
{
   fprintf(stderr, "Received error: %s\n",
                    lcb_strerror(instance, error));
   if (errinfo) {
      fprintf(stderr, "   (%s)\n", errinfo);
   }
   ... handle error ...
}
...
lcb_t instance;
...
lcb_set_error_callback(instance, callback);
...

ATTRIBUTES

See lcb_attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE ATTRIBUTE VALUE

Interface Stability

Committed

MT-Level

MT-Safe

COPYRIGHT

Copyright 2010-2013 Couchbase, Inc.

SEE ALSO

Learn more at http://www.couchbase.com/communities/c.

libcouchbase(3lib), lcb_error(3couchbase), lcb_strerror(3couchbase), lcb_attributes(5)