XQuery runtime errors can be processed via ''error annotations''. A single argument must be supplied, which represents the QName of the error to be caught. A wildcard {{Code|*}} may be specified to catch all possible errors. A function can only have a single error annotation.: <pre class="brush:xquery">declare %rest:error("*") function page:error() { "An error occurred while processing your RESTXQ code!"};</pre><!-- TODO how matching works -->
The XQuery [[XQuery 3.0#Try.2FCatch|try/catch]] construct assigns error information to a number of pre-defined variables ({{Code|code}}, {{Code|description}}, {{Code|value}}, {{Code|module}}, {{Code|line-number}}, {{Code|column-number}}, {{Code|additional}}). These variables can be bound to variables via ''error parameter annotations'', which are specified the same way as [[#Query Parameters|query parameters]].