Handling exceptions in reflexive extension functions
If a Java extension function throws an exception, the exception can be caught using the try/catch facilities in XQuery 3.0 and XSLT 3.0.
The exception triggers a dynamic error, whose details are derived from the exception details:
-
The error code (
err:code
) is a QName whose namespace URI is"http://saxon.sf.net/java-type
and whose local name is the class name of the exception type, for examplejava.net.URISyntaxException
. -
The error description (
err:description
includes the content of the exception message, with a prefix to identify the extension function that was called. -
The error object (
err:value
) is the wrapped Java object whose method was being invoked in the case of an instance method, or the wrapped Java Class object in the case of a static method or constructor.
Note that this applies to cases where the extension function is successfully called, and the called function throws an exception. Failures to invoke the extension function are mapped to Saxon error codes and the original Java exception is not directly available.