Re: [xsl] ex:error-safe (was: saxon:try())

Subject: Re: [xsl] ex:error-safe (was: saxon:try())
From: Florent Georges <lists@xxxxxxxxxxxx>
Date: Wed, 9 Jan 2008 18:54:48 +0100 (CET)
Colin Adams wrote:


> > >   If you want to prevent the global variable
> > > evaluation to throw an error, use something like this:

> > > <xsl:variable name="v" as="node()"/>
> > >    <ex:error-safe>
> > >       <ex:try>
> > >          <xsl:sequence select="error()"/>
> > >       </ex:try>
> > >       <ex:catch>
> > >          <xsl:sequence select="'alternative value'"/>
> > >       </ex:catch>
> > >    </ex:error-safe>
> > > </xsl:variable>

> The problem with this is that, in general, you don't know
> whether or not it is right to catch the error. The
> accessor of the variable might be in a different module,
> by a different author.

> You won't always be able to guess what is best for the
> user of the module.

  I think we have just different points of view.

  IMHO, a global variable declaration defines a value.
Either the value can be defined using some try/catch
mecanism (for instance providing () in case of error),
either the transform should fail in case of error while
evaluating the value.

  If this is not possible, and the variable writer want to
let the user the chance to catch the error, it should
instead use a function.

  I know that a function with now argument could be view as
a global variable in a functional language without
side-effects.  The difference here occurs only on regard of
the error handling, because of this error handling is
defined (differently for variables and functions).

  I don't think this is really confusing: the error context
while evaluating a variable value is the error context where
the variable is declared, and for functions it is the error
context of the function call.

  I think this is even quite intuitive (it seems just we
don't have the same intuition on this :-p):

    <xsl:variable name="v" select="error()"/>

    <xsl:function name="my:f">
       <xsl:sequence select="error()"/>

    <xsl:template match="/">
             <xsl:sequence select="$v, my:f()"/>

  IMHO the error of evaluating $v should not be caught,
while the error of evaluating my:f() should.



Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail

Current Thread