Hi i would like to know what is the best practice to handle exceptions in Struts based applications.
I have defined ExceptionMappingInterceptor aka exception interceptor and it works but it can not handle all kind of exceptions. I would like to have various exceptions that can occur in various parts of my system handled in an uniform manner and and my only requirements are: have these exceptions logged and present user simple error page. ExceptionMappingInterceptor is not able to satisfy my requirements in these 2 cases: 1) If no action with given URL is defined in struts.xml i see on a screen *:There is no Action mapped for namespace / and action name {actionName}. - [unknown location] and stacktrace that begins with : * com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186) org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:494) org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419) com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190) com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130) Full stacktrace is logged.by my logger but http response code is 200 2) I am using Spring plugin and my actions are spring managed bean. If there is any spring related error in my actions (spring beans) i got an error message on screen, Http response is 500 now and i see stacktrace in my SystemOut.log : at com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:294) at com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:365) at com.opensymphony.xwork2.DefaultActionInvocation.access$000(DefaultActionInvocation.java:38) at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:83) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.<init>(DefaultActionInvocation.java:74) at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189) at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:494) at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419) at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190) at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130) I would like to have various exceptions that can occur in various parts of my system handled in an uniform manner. What is the best practice to handle all these exceptions? Up to now i have defined ExceptionMappingInterceptor interceptor and it satisfies all my requirements but it only works when exceptions are thrown from actions. In case 2 (spring managed action classes) i can define error-page element in web.xml to handle errors with code 500 and have it redirected to the same page as defined in ExceptionMappingInterceptor interceptor. This configuration does not catch exception mentioned in case 1, but also has small drawback: address of error page to present user is duplicated in struts.xml and web.xml. Can someone provide any ideas/hints/explanations?