Hello,
I am playing with libcouchbase within a C++ environment (gcc). I am struggling to understand how to implement a simple way to make libcouchbase compatible with C++ exceptions.
Libcouchbase uses an asynchronous model, with callbacks. The callbacks are called from libcouchbase’s C code. It is straightforward to call libcouchbase from C++ and write C++ callbacks, but if these callbacks trigger exceptions, they do not cross libcouchbase’s asynchronous model and C code well…
Am I missing something?
Thanks!
libcouchbase uses a C internally, and therefore there isn’t any support for exceptions - which involve things like unwinding the stack. The best approach is to store any kind of error information in the user cookie
object and then raise them once you are no longer in the library’s event loops.
In order for exceptions to work properly, everything would need to be C++ (including libcouchbase itself and the event loop being used).
Note, I am moving the library’s internals to C++ slowly, but even then the event loop (e.g. libevent, etc.) may be in C, and wouldn’t participate well with stack unwinding.
1 Like