Results 1 to 2 of 2

Thread: DispatcherServlet/Exception Handlers/Rendering

  1. #1
    Join Date
    Sep 2005
    Posts
    1

    Default DispatcherServlet/Exception Handlers/Rendering

    I am surprised to find that even though I have an Exception Handler registered,
    exceptions thrown while rendering a velocity template do not get handled.
    Looking at the code for DispatcherServlet.doDispatch, I see:


    }
    catch (Exception ex) {
    Object handler = (mappedHandler != null ? mappedHandler.getHandler() : null);
    mv = processHandlerException(request, response, handler, ex);
    }

    // Did the handler return a view to render?
    if (mv != null && !mv.isEmpty()) {
    render(mv, processedRequest, response);
    }


    Why aren't exceptions from the render call also caught and handled? Is this an
    oversight or is there a good reason?

  2. #2
    Join Date
    May 2005
    Location
    SLC, UT, USA
    Posts
    7

    Default Just a guess as to why they don't handle render excpetions

    I have the same question. My guess as to why they don't handle is that if the rendering method has alreay started to do somethign with the output stream then any type of forward to an error handler wouldn't work.

    What I did was since the controller knows what view to use (or at least the view name) it can call the approp view.render method directly so that if it throws the exception will be caught by the exception resolver. My exception resolver/handler then grabs the approp error info and puts it into the session. I then do a redirect to an error jsp which pulls the data out of the session for display.

    I'd still like to know why they don't / how come they won't give the error resolver a chance to handle.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •