[MarkLogic Dev General] fn:error and error code

Ron Hitchens ron at ronsoft.com
Tue Mar 6 14:05:59 PST 2012


   This is for historical reasons.  The signature
of fn:error() changed when XQuery 1.0 was finalized.
MarkLogic already had code in place with error codes
that were ML-specific.

   To be compatible with XQuery 1.0, the new xs:QName
parameter had to be accommodated.  So the value of the
QName wound up as error:name and the pre-existing ML
codes are in error:code.  If you use the 2 or 3 arg
version of fn:error, your description goes in the 
error:code slot.

   The W3C spec defines the meanings of certain QNames,
and where possible those were mapped to existing error
codes, like your divide by zero example below.

   To make things even more complicated, MarkLogic had
a defined error namespace, but XQuery 1.0 defined a
different one.  I thing there is some variation in
the XML you get for an error depending on whether you're
running as 1.0 or 1.0-ml.

   In Xquery 3.0, I have no idea what's happening...

On Mar 6, 2012, at 6:33 PM, Geert Josten wrote:

> Hi Steve,
>  
> Even worse. The built-in errors have a different layout:
>  
>   <error:code>XDMP-DIVBYZERO</error:code>
>   <error:name>err:FOAR0001</error:name>
>   <error:message>Division by zero</error:message>
>  
> For those from fn:error the code and message element have same contents. To my knowledge this has always been like this. Not sure why. I reccon it is a bit late to change it now..
>  
> Kind regards,
> Geert
>  
> Van: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] NamensSteve Spigarelli
> Verzonden: dinsdag 6 maart 2012 19:25
> Aan: general at developer.marklogic.com
> Onderwerp: [MarkLogic Dev General] fn:error and error code
>  
> I've noticed that in the documentation for the fn:error function that the first parameter can be an xs:QName for the error code. However, when I xdmp:log the caught error I get the code in the name and the name in the code field.
>  
> Here is the code that I'm running:
>  
> xquery version "1.0-ml";
>  
> module namespace test = "test-error";
>  
> declare function test-error() {
>     try {
>     fn:error(xs:QName("MY-ERROR"), "my test error", ())
>     } catch ($e) {
>         xdmp:log($e)
>     }
> };
>  
> and here is what I get in the resulting error xml:
>  
> ...
> <error:code>my test error</error:code>
>   <error:name>MY-ERROR</error:name>
> ...
>  
>  
> Any idea why this works this way?
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general

---
Ron Hitchens {mailto:ron at ronsoft.com}   Ronsoft Technologies
     +44 7879 358 212 (voice)          http://www.ronsoft.com
     +1 707 924 3878 (fax)              Bit Twiddling At Its Finest
"No amount of belief establishes any fact." -Unknown






More information about the General mailing list