saxon:try()

This function is available only in Saxon-EE

This function provides a simple way of recovering from dynamic errors (including type errors).

try($arg1 as item()*, $arg2 as item()*) ==> item()*

This returns the value of the first argument, unless evaluation of the first argument fails. If a failure occurs, then the second argument is evaluated and its value is returned.

Here is an example showing the simpler form of call: the expression saxon:try(1 div 0, "divide by zero") returns the string "divide by zero".

To recover from failures occurring in XSLT instructions, for example schema validation errors, wrap the instructions in a stylesheet function (xsl:function) and call this function within a call of saxon:try().

In XSLT, a more flexible mechanism for catching errors is the saxon:try extension instruction. In XQuery, a more flexible mechanism is the XQuery 1.1 try{} expression.