Re: What is the call-site of errors in sequences?

> On 22 Sep 2016, at 15:45, Abel Braaksma <abel.braaksma@xs4all.nl> wrote:
> 
> That implies that the following will return "eager-throw":
>  
> <xsl:try>
>     <xsl:for-each select="1,2,error(xs:QName('err:test3')),4,error(xs:QName('err:test5'))">
>        <xsl:try>
>           <xsl:value-of select="." />
>           <xsl:catch>
>              <xsl:value-of select=" 'lazy-throw' " />
>           </xsl:catch>
>        </xsl:try>
>     </xsl:for-each>
>     <xsl:catch>
>        <xsl:sequence select="'eager-throw'" />
>     </xsl:catch>
> </xsl:try>
>  
> I am not sure this is either intuitive or useful (if compared with the $errors variable approach).

It seems right to me, in terms of what most users will expect. If you evaluate an expression that causes an error, you expect it to be caught by the nearest enclosing xsl:try. That's what xsl:try means: "try this".


> I mean, it seems to make sense being able to pass around a sequence that includes errors,

If you want to do that, then pass a function that throws the error when called.


> 
> Again, it feels a bit as if the XPath rules are (somewhat) in conflict with the XSLT rules, though I am not certain if, or how this could/should be fixed.

I don't see a conflict. XPath doesn't have try/catch but I'm pretty confident the XSLT rules are consistent with the XQuery rules.
>  
> But if $seq and $catch were XPath expressions (that is, not a variable), they could work.
>  

try/catch definitely implies a loss of referential transparency, in that you can't simply inline a variable reference without considering the try/catch context. I think if we were to try and model it formally we would say that the dynamic context includes a catch-context, which is a mapping from error codes to something (functions?), and if a dynamic error occurs in an expression then the result of the expression is determined by the catch-context.

This DOESN'T necessarily imply eager evaluation; it does imply that expressions are evaluated with the correct catch-context.

Michael Kay
Saxonica

Received on Thursday, 22 September 2016 15:38:06 UTC