You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "Peter C. Verhage" <pe...@zeelandnet.nl> on 2001/03/28 21:38:47 UTC

Cocoon 1.x & Exceptions

At the moment if there is an Exception somewhere in your page, Cocoon will
show the Exception message or (if you have configured Cocoon that way) it
will generate a HTTP error response.

I tried to change this kind of behaviour a bit in my taglib. I do this
adding to the root of my taglib a catch / try block for a special internal
Exception type. This kinda works. As soon as there is an (special) Exception
it gets caught, my code looks something like this:

try
{
  ...
}
catch (MyException E)
{
 <error>
   <xsp:attribute
name="id"><xsp:expr>E.getErrorCode()</xsp:expr></xsp:attribute>
   <xsp:expr>E.getMessage()</xsp:expr>
 </error>
}

As you can see I add an XML node named "error" to the XML tree.
Unfortunately it will get's placed at the position until where the page is
processed. What I mean is like this:

try
{
  ...
  <some-xml-here>
    <blub/><blab/>
    <some-more-xml>
      <xsp:logic>
        java code that generates the exception
      </xsp:logic>
    </some-more-xml>
  </some-xml-here>
}
catch
{
 ...
}

Will return something like this:
<root-tag>
  <some-xml-here>
    <blub/><blab/>
    <error id="...">...</error>
  </some-xml-here>
</root-tag>

Instead I want something like this:
<root-tag>
  <error id="...">...</error>
</root-tag>

Because if I have an XML fragment like this it's much more easy to process
in my stylesheet, and show a much more friendly error message then Cocoon
does. But because I don't know exactly where the Exception occured within
the XML fragment the error element could be everywhere, and I'm not even
sure if there was an error!

Is there a way to throw every pre-generated XML away, and just put the error
node on top of the stack? So I only have to do a check if the root node, or
the first node within the root node is the error node or not...

I know Cocoon 2 will make it possible to do this kind of behaviour, but at
the moment I'm stuck with Cocoon 1.x and I think this could be a really
clean solution if I just can clear the stack somehow...

Regards,

Peter


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>