PhoenixmlDb.Core

XQueryException

Thrown when an XQuery expression fails to parse or encounters a runtime error during execution.

#XQueryException

Namespace: PhoenixmlDb.Core

Thrown when an XQuery expression fails to parse or encounters a runtime error during execution.

When it's thrown: By IContainer.QueryAsync and IReadTransaction.QueryAsync when the XQuery expression has a syntax error, a type error, a dynamic error (e.g., division by zero), or references an undeclared variable or function.

Debugging information: This exception provides structured error details:

  • XQueryException.ErrorCode — the W3C-defined error code (e.g., "XPST0003" for syntax errors, "XPDY0002" for dynamic errors, "FOAR0002" for division by zero). See the XQuery specification for the full error code catalog.

  • XQueryException.Line — the line number in the query where the error was detected (1-based).

  • XQueryException.Column — the column number within that line (1-based).

How to handle it: Log the full exception message (which includes the error code and location). For user-facing query interfaces, display the error code and location to help users fix their queries. For application-embedded queries, this usually indicates a bug in the query string.

#Example

csharp
try
{
    await foreach (var result in container.QueryAsync("//product[price >"))
    {
        Console.WriteLine(result);
    }
}
catch (XQueryException ex)
{
    Console.WriteLine($"Query error [{ex.ErrorCode}] at line {ex.Line}, column {ex.Column}");
    Console.WriteLine(ex.Message);
}