Hi there
I want to avoid that my application gets terminated on uncaught exceptions. I couldn't find any documentation about how to set the abort handler. So it seems that I'm doing this wrong:
In my main C file:
#include ... #include <zdb.h>
void(*AbortHandler)(const char *error);
void myhandler(const char *error) { fprintf(stdout, "...%sn", error); }
main () { AbortHandler = myhandler; }
But the handler is not used and the program ends: SQLException: mysql_stmt_fetch -- Incorrect number of arguments for FUNCTION cpr_db.consolidate_occupancy; expected 2, got 1 raised in _next at src/db/mysql/MysqlResultSet.c:209
What's the correct way to set the external AbortHandler in main()?
Cheers Till
Call ConnectionPool_setAbortHandler with your handler. The handler is a last resort and you should try to catch exceptions as they _do_ indicate a runtime error.
See https://www.tildeslash.com/libzdb/api-docs/ConnectionPool_8h.html#a23b8c11de...
Example: ---
static void abortHandler(const char* error) { fprintf(stdout, "Error: %s\n", error); }
//…
ConnectionPool_T pool = ConnectionPool_new(URL_new("mysql://localhost/test?user=root&password=swordfish"));
// Sets the abortHandler to prevent uncaught exceptions to terminate the app/library ConnectionPool_setAbortHandler(pool, abortHandler);
ConnectionPool_start(pool);
On 28 Jun 2025, at 01:24, g4-lisz@tonarchiv.ch wrote:
Hi there
I want to avoid that my application gets terminated on uncaught exceptions. I couldn't find any documentation about how to set the abort handler. So it seems that I'm doing this wrong:
In my main C file:
#include ... #include <zdb.h>
void(*AbortHandler)(const char *error);
void myhandler(const char *error) { fprintf(stdout, "...%s\n", error); }
main () { AbortHandler = myhandler; }
But the handler is not used and the program ends: SQLException: mysql_stmt_fetch -- Incorrect number of arguments for FUNCTION cpr_db.consolidate_occupancy; expected 2, got 1 raised in _next at src/db/mysql/MysqlResultSet.c:209
What's the correct way to set the external AbortHandler in main()?
Cheers Till
Thanks!
RTFM ;) I don't know why I couldn't find it. I didn't expect it in the ConnectionPool header, I guess...
And of course you are right: I should catch them all in my code. I thought I did, but I didn't realize that ResultSet_next() can also throw exceptions.
RTFM one more time...
Best regards Till
June 28, 2025 5:07 PM, "Jan-Henrik Haukeland" hauk@tildeslash.com wrote:
Call ConnectionPool_setAbortHandler with your handler. The handler is a last resort and you should try to catch exceptions as they _do_ indicate a runtime error.
See https://www.tildeslash.com/libzdb/api-docs/ConnectionPool_8h.html#a23b8c11de...
Example:
static void abortHandler(const char* error) { fprintf(stdout, "Error: %s\n", error); }
//…
ConnectionPool_T pool = ConnectionPool_new(URL_new("mysql://localhost/test?user=root&password=swordfish"));
// Sets the abortHandler to prevent uncaught exceptions to terminate the app/library ConnectionPool_setAbortHandler(pool, abortHandler);
ConnectionPool_start(pool);
On 28 Jun 2025, at 01:24, g4-lisz@tonarchiv.ch wrote:
Hi there
I want to avoid that my application gets terminated on uncaught exceptions. I couldn't find any documentation about how to set the abort handler. So it seems that I'm doing this wrong:
In my main C file:
#include ... #include <zdb.h>
void(*AbortHandler)(const char *error);
void myhandler(const char *error) { fprintf(stdout, "...%s\n", error); }
main () { AbortHandler = myhandler; }
But the handler is not used and the program ends: SQLException: mysql_stmt_fetch -- Incorrect number of arguments for FUNCTION cpr_db.consolidate_occupancy; expected 2, got 1 raised in _next at src/db/mysql/MysqlResultSet.c:209
What's the correct way to set the external AbortHandler in main()?
Cheers Till