Exception handling in libBasexCpp
Monday, 20 July 2026 · 3 messages
BE
Ben Engbers20 Jul 2026 16:23 #
Hi,
I know that Session.Execute(QueryID, "for $line in doc('" + TestDB + "/Test.xml')//Line return $line") will result in an error since Test.xml does not exist.
The Basexserver returns this message:
FATAAL: Stopped at ., 1/17:
[basex:doc] Database path 'TestCppClient_3/Test.xml' yields no documents.
This is my BasexClient::Execute method and my assumption was that the error would result from calling this method, and specifically from calling `handshake`.:
ResultsObject_Uptr BasexClient::Execute (const ByteVect & QueryID) {
ByteVect exec, result;
pushByte (HEX_EXEC, exec).addVoid (QueryID, exec);
try {
handShake (exec, result); }
catch (const std::exception& e) {
throw BasexException("BaseX-fout: " + std::string(e.what())); }
catch (...) {
throw BasexException("Unknown error while communicating with
Basex.");
};Introducing the try-catch did not result in changed output in my testapplication..
Is there a proper way to handle errors from Basexserver?
Ben
CG
Christian Grün20 Jul 2026 16:35 #
Hi Ben,
Catch has nothing to catch, as BaseX never throws an error at the socket: When a query fails, it still sends a normal, complete response (the error is just a flag byte inside it).
After EXEC, the server sends:
1. the result, ending with 0x00
2. one status byte (0 = OK, otherwise error)
3. the error message (ending with 0x00) …if the status byte was non-zero.
Hope this helps,
Christian
Quoted text · Ben Engbers · 29 lines
Von: Ben Engbers via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> Gesendet: Montag, 20. Juli 2026 16:23 An: Basex Mail-lijst Betreff: [basex-talk] Exception handling in libBasexCpp Hi, I know that Session.Execute(QueryID, "for $line in doc('" + TestDB + "/Test.xml')//Line return $line") will result in an error since Test.xml does not exist. The Basexserver returns this message: FATAAL: Stopped at ., 1/17: [basex:doc] Database path 'TestCppClient_3/Test.xml' yields no documents. This is my BasexClient::Execute method and my assumption was that the error would result from calling this method, and specifically from calling `handshake`.: ResultsObject_Uptr BasexClient::Execute (const ByteVect & QueryID) { ByteVect exec, result; pushByte (HEX_EXEC, exec).addVoid (QueryID, exec); try { handShake (exec, result); } catch (const std::exception& e) { throw BasexException("BaseX-fout: " + std::string(e.what())); } catch (...) { throw BasexException("Unknown error while communicating with Basex."); }; Introducing the try-catch did not result in changed output in my testapplication.. Is there a proper way to handle errors from Basexserver? Ben
BE
Ben Engbers20 Jul 2026 18:18 #
I have alreay implemented the error-handling this way.
The benefit of exceptionhandling in C++ (as far as I understand) is that when an exception is thrown, the connectons are claused and all the resources are cleaned up by the compiler.
So I guess I'll have to convert the Basex non-zero response to an exception (this shouldn't be too difficult).
Until now, all exceptions that were thrown, were FATAL.
Are there also WARNINGS? Do you have a list of error-messages with attribute FATAL or WARNING?
Ben
Quoted text · Christian Grün · 17 lines
Op 20-07-2026 om 16:35 schreef Christian Grün: > Hi Ben, > > Catch has nothing to catch, as BaseX never throws an error at the socket: When a query fails, it still sends a normal, complete response (the error is just a flag byte inside it). > > After EXEC, the server sends: > 1. the result, ending with 0x00 > 2. one status byte (0 = OK, otherwise error) > 3. the error message (ending with 0x00) …if the status byte was non-zero. > > Hope this helps, > Christian > ________________________________________ > Von: Ben Engbers via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> > Gesendet: Montag, 20. Juli 2026 16:23 > An: Basex Mail-lijst > Betreff: [basex-talk] Exception handling in libBasexCpp
--
Ben Engbers
Grietjeshof 77
6721 VH Bennekom
+31 6 23634840
Written for BaseX 12.4. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery