Database Reference
In-Depth Information
following example shows a try / catch usage example that sets a variable to -1 if a
division-by-zero error occurs:
let $ result as xs:decimal :=
try
{
$ something div $ something-else
}
catch err:FOAR0001 { - 1 }
This example tests for a very specific error, which is good, because we would like a
warning when something unexpectedly goes wrong. If you want to test for all errors
that can occur, change the err:FOAR0001 into an * .
If you want to test for a specific error condition but don't know its
code, probably the easiest way to find it is to force the error and
copy the error code reported back into the XQuery.
Inside the catch operand you have access to information about the error through a
number of implicitly declared variables— $err:code , $err:line-number ,
$err:column-number , $err:description , $err:value , $err:module , and $err:addi
tional . Please refer to the XQuery 3.0 specification for full details.
switch expression
The XQuery 3.0 switch expression implements that which in other languages is often
called a case expression or, in XSLT, an xsl:choose . This example was copied from
the XQuery 3.0 specification:
switch ( $ animal )
case "Cow" return "Moo"
case "Cat" return "Meow"
case "Duck" return "Quack"
default return "What's that odd noise?"
Higher-order functions
A higher-order function is a function that takes another function as a parameter or
returns a function. The normal use case for this is mapping or filter functions. Here is
an example:
declare function local:map-example ( $ func , $ list ) {
for $ item in $ list
return
$ func ( $ item )
};
Search WWH ::




Custom Search