text: fn:error( [error as xs:QName?], [description as xs:string], [data as item()*] ) as empty-sequence()
  [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.
  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.
  Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.