home contribute faq download

FunctX XQuery Functions

fn:error

Raises a custom error

Google
Webdatypic.com

Description

The fn:error function allows you to stop execution of the query, with a specific error message. This is useful if an unexpected or invalid condition exists, such as a missing or invalid data item. You can incorporate calls to the fn:error function in your query to signal such problems to the query user.

It is implementation-dependent how a processor will use the optional $description and $error-object arguments. Most processors will report the $description as part of the error message to the user.

Some processors may report the error name as a URI, where the local part is a fragment identifier, as in http://datypic.com/err#ProdNumReq.

The fn:error function is the same function that the processor calls implicitly whenever there is an error during query evaluation. The return type of none is only used for the fn:error function and is not available to query authors. It simply means that the fn:error function never returns any value; evaluation of the query stops once the fn:error function is called.

This description is © Copyright 2007, Priscilla Walmsley. It is excerpted from the book XQuery by Priscilla Walmsley, O'Reilly, 2007. For a complete explanation of this function, please refer to Appendix A of the book.

Arguments and Return Type

NameTypeDescription
$error xs:QName a qualified name for the error
$description xs:string a description of the error
$error-object item()* the item(s) that raised the error
return value none

Examples

XQuery ExampleResultsExplanation
error()
Error
error(xs:QName('dty:ProdNumReq')) 
Error Assumes the dty prefix has been declared.
error(
   QName('http://datypic.com/err',
         'ProdNumReq'),
   'Missing number.')
Error
error(
   QName('http://datypic.com/err',
         'ProdNumReq'),
   'Missing number.', $prod)
Error

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26W3C, XQuery 1.0 and XPath 2.0 Functions and Operators, http://www.w3.org/TR/xpath-functions/
Datypic XQuery Services

Recommended Reading:

XQuery