This page was generated
August  8,  2011
2:24  AM
XQuery Built-In and Modules Function Reference

Built-In: Error and Trace

The error and trace built-in functions are XQuery functions defined for throwing errors from XQuery programs and debug tracing. They are defined in XQuery 1.0 and XPath 2.0 Functions and Operators.

The error and trace built-in functions use the fn namespace prefix, which is predefined in the server. Also, the fn prefix is the default prefix for function calls if none is specified.

Function Summary
fn:error [1.0 and 1.0-ml only, 0.9-ml has a different signature] Throw the given error.
fn:trace Return the input $value unchanged and, if $label is the name of an enabled server event, emit that server event to the server log file (ErrorLog.txt) with $value as its data.
Function Detail
fn:error(
[$error as xs:QName?],
[$description as xs:string],
[$data as item()*]
)  as   empty-sequence()
Summary:

[1.0 and 1.0-ml only, 0.9-ml has a different signature] Throw the given error. When an error is thrown, the XQuery program execution is stopped. For detailed semantics, see http://www.w3.org/TR/xpath-functions/#func-error.

Parameters:
$error (optional): Error code, as an xs:QName. Note that this parameter does not exist in 0.9-ml.
$description (optional): String description to be printed with the error.
$data (optional): Parameters to the error message.

Example:
xquery version "1.0-ml";
let $x := xdmp:random(100)
return
(
if ( $x gt 50 ) 
then ( fn:error(xs:QName("ERROR"), "greater than 50") )
else ( "Less than or equal to 50" ) ,
": no error was thrown" )

=> The error when the random number is greater
   than 50.

fn:trace(
$value as item()*,
$label as xs:string
)  as   item()*
Summary:

Return the input $value unchanged and, if $label is the name of an enabled server event, emit that server event to the server log file (ErrorLog.txt) with $value as its data.

Parameters:
$value : The values to trace.
$label : A string label for the trace output.

Usage Notes:

In order for the trace event to print out in the log file, you must enable the trace event in the Diagnostics page (Groups > group_name > Diagnostics ) of the Admin interface for the specified label.

Example:
fn:trace("This is a trace event.", "MY TRACE EVENT")

=> If MY TRACE EVENT is defined as an enabled trace event
   in the Diagnostics page of the Admin interface, then a
   message similar to the following is added to the 
   ErrorLog.txt file:

   2006-03-20 17:56:09.346 Info: [Event:id=MY TRACE EVENT] 
                                 This is a trace event.