Hello! As I understand it, the abort handler is the only way catch fatal errors in the library, like the inability to connect to the server or something similar. Its a simple C function pointer.
The problem I have with this is that I use the library from within Objective-C classes and I want my objects to handle possible errors. I can't see a practical way to redirect the control flow back to my object in such a case.
A lot of libraries that work with handler functions give you the opportunity to pass along with the function pointer a user data object that will be provided to the handler when invoked. It would be nice to see something similar for the abort handler because at the moment I am limited in how I can react to fatal errors in zdb.
Best regards, Jacob
On Jun 14, 2013, at 3:51 PM, Jacob M. H. Smith jacob.m.h.smith@gmail.com wrote:
Hello! As I understand it, the abort handler is the only way catch fatal errors in the library, like the inability to connect to the server or something similar. Its a simple C function pointer.
Actually, the abort handler is a last resort and the proper way to catch errors is to use exceptions. From version 2.10.x of the library, ConnectionPool_start now also throws an exception if the library cannot connect to the database server. You can read more about exceptions and how they are used in the library here, http://www.tildeslash.com/libzdb/api-docs/Exception_8h.html
I do agree that the abort handler could benefit from taking an extra void pointer as a context parameter, but that context would still need to be application wide as you can only register once. So the benefit is limited. Exceptions on the other hand will transfer control right up the call stack, back to the obj-c object and method calling libzdb.
In practice the abort handler is only useful if memory cannot be allocated, which "never" happens on a server/desktop which uses virtual memory. If you use libzdb on iOS or similar then it is another story, but even then if you wrap calls to libzdb in a try-else block, you can also catch memory exceptions.
TRY code that can throw exception ELSE catches any exception also OOM END_TRY