You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andrew Hill <an...@gridnode.com> on 2002/10/29 07:08:00 UTC

ExceptionHandler & DispatchAction (1.1b1 vs b2)

Been trying to get my first struts ExceptionHandler to work today and just
came across another good reason to make the jump from 1.1b1 to 1.1b2.

Seems that exceptions thrown in a DispatchAction are handled correctly in
1.1b2 (ie: if possible thrown up where you can process them with an
exception handler) while 1.1b1 always writes an error response out
immediately using response.sendError() , thus preventing the exception
bubbling up to where the RequestProcessor can pass it to your
ExceptionHandler like it does for an Action.

Many cheers to the struts devs for fixing this! :-)

1.1b1 Code:
-----------
<snip>
} catch (InvocationTargetException e)
        {
            String message =
                messages.getMessage("dispatch.error", mapping.getPath(),
                                    name);
            log.error(message, e);
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                               message);
            return (null);
        }
</snip>

1.1b2 Code:
-----------
<snip>
} catch (InvocationTargetException e) {
            // Rethrow the target exception if possible so that the
            // exception handling machinery can deal with it
            Throwable t = e.getTargetException();
            if (t instanceof Exception) {
                throw ((Exception) t);
            } else {
                String message =
                    messages.getMessage("dispatch.error", mapping.getPath(),
                                        name);
                log.error(message, e);
                response.sendError
                    (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
                return (null);
            }
</snip>







<btw>
<whinge subject="coding.style">
I really can't stand this sun style java indenting thats used in the struts
source. Its so random and unreadable and ugly. Trying to scan more than a
few lines of it really gives me a headache. Id rather debug BF code (well ok
I wouldnt but at least BF doesnt pretend to be readable...)
When Im dictator for life everyone will have to use C style indenting and
put their curlies back where they belong...<sigh/>
</whinge>
</btw>


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