PDA

View Full Version : Redirecting to custom Exception Controller


lindbird
Feb 9th, 2006, 02:33 PM
Hello, I am trying to implement a controller which handles all exceptions resolved by a SimpleMappingExceptionResolver:

<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMapp ingExceptionResolver">
<property name="defaultErrorView">
<value>redirect:errors.do</value>
</property>
<property name="exceptionAttribute">
<value>myException</value>
</property>
</bean>


I have mapped a controller to "errors.do" which extends AbstractController:

<bean id="myErrorsController" class="ui.controller.MyErrorsController">
<property name="view">
<value>error/default-error</value>
</property>
</bean>


My question is how do I get the original thrown exception to my errors controller so I can process it. I know I could extend SimpleMappingExceptionResolver and put it into session or something, but I was under the assumption that I had access to the exception through the model... I thought that the exceptionAttribute had something to do with it but I guess not... any suggestions?

thanks,
Ryan

dhewitt
Feb 9th, 2006, 02:45 PM
The exceptionAttribute gives the name in the Model with which the Exception will be bound. Unfortunately, your view is a RedirectView - so everything in the model (request scope) is lost. A string representation of the Exception should automatically be added to the request parameters on redirect, by the RedirectView, but this may or may not be useful to you.

As far as I can see you'll have to subclass the ExceptionResolver to put the exception in the session, and then get your controller to retrieve it and unbind it from the session again.