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.
fn
xs:QName
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.
ErrorLog.txt
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.