When something goes wrong, an exception of
CouchbaseError is typically thrown. The
exception object contains a lot of information that can be used
to find out what went wrong.
from couchbase import Couchbase from couchbase.exceptions import CouchbaseError c = Couchbase.connect(bucket='default') try: # Will fail because 'object' is not JSON-serializable c.set("key", object()) except CouchbaseError as e: print e
Printing the exception object typically produces something like this:
# line breaks inserted for clarity <Couldn't encode value, inner_cause=<object object at 0x7f873cf220d0> is not JSON serializable, C Source=(src/convert.c,131), OBJ=<object object at 0x7f873cf220d0> >
The exception object consists of the following properties:
This is the message, if any, that indicates what went wrong. It is always a string.
>>> e.message "Couldn't encode value"
If this exception is triggered by another exception, this field contains it. In the above example, we see the exception
>>> e.inner_cause TypeError('<object object at 0x7f873cf220d0> is not JSON serializable',)
If present, contains the source code information where the exception was raised. This is only present for exceptions raised from within the C extension.
>>> e.csrc_info ('src/convert.c', 131)
Contains the Python object that likely caused the exception. If present, it means the object was of an invalid type or format.
>>> e.objextra <object object at 0x7f873cf220d0>