Hi Jan-Henrik
Thank you so much for your detailed explanation! That completely cleared up the question for me.
And I adjusted my code accordingly. I.e. I replaced all the CATCH() and Connection_getLastError().
Cheers, Till
June 24, 2025 4:29 PM, "Jan-Henrik Haukeland" hauk@tildeslash.com wrote:
On 23 Jun 2025, at 17:37, g4-lisz@tonarchiv.ch wrote:
- There was a time when libzdb did not use exceptions, and Connection_getLastError() harked back
to that time. Today, always prefer Exception_frame.message. Connection_getLastError() is now more of an internal function.
Connection_getLastError() returns any database errors (or “?”) on the current connection, while Exception_frame.message returns database errors _and_ API errors such as parameter or column index out of bounds, pool is full, etc.
- BTW, don’t bother catching individual Exceptions; just use ELSE to make the code simpler, unless
you want to fail on an AssertException. I.e. use TRY-ELSE:
TRY { // Code that can throw exception } ELSE { printf("Exception -- %s\n", Exception_frame.message); } END_TRY;
If you use TRY-CATCH (SQLException) then you will also not catch any AssertException and the app with call the Abort Handler, if installed, or abort.
so I can't safely use Connection_getLastError() there.
You can safely call Connection_getLastError() from anywhere, but unless there was a database error it might not return anything useful.
Jan-Henrik