MarkLogic Server
XQUERY API DOCUMENTATION
3.2
This page was generated
January 5, 2009
5:42 PM
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 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(
[$code as item()?],
[$data as item()*]
)  as  empty()
Summary:

Throw the given error. When an error is thrown, the XQuery program execution is stopped.

Parameters:
$code (optional): Error code or string.
$data (optional): Parameters to the error message.

Example:
let $x := xdmp:random(100)
return
if ( $x gt 50 ) 
then ( fn:error("ERROR", "greater than 50") )
else ( "Less than or equal to 50" )

=> 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.