Can't you throw a RuntimeException with the original exception as its cause from the error() method?

  Claude

On 2011-06-16 23:47, Christopher Schultz wrote:
All,

I'm using a Velocity template as part of a process that looks like this:

1. Accept batch request in XML format
2. For each item in the batch:
  2a. Process the item
  2b. Report the results in XML format

I'm using a custom servlet to manage this flow and step 2b is being done
like this:

   // several request.setAttribute() calls
   try
   {
     request.getRequestDispatcher("/my/velocity.vm").include(req, rsp);
   }
   catch (Exception e)
   {
     // write the error as XML elements
   }

Unfortunately, the VelocityViewServlet is catching exception (such as
ParseErrorException) and rendering an HTML-appropriate response to the
output stream.

That makes my XML hard to manage.

At first, I thought "oh, okay, just subclass and override
VelocityViewServlet.error and make it throw an exception. Unfortunately,
that method isn't allowed to throw any exceptions.

It looks like my options are:

1. Subclass and override error() and use the request attributes
    to report errors to the caller.

2. Subclass and override doRequest() and basically re-implement it,
    wrapping any exceptions in a RuntimeException (or IOException, I
    guess)

Neither of these options are very palatable for me, honestly. For #2, if
doRequest threw ServletException as well as IOException, that would at
least be more appropriate.

Does anyone have any other suggestions?

Thanks,
-chris



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org
For additional commands, e-mail: user-h...@velocity.apache.org

Reply via email to