2013/10/29 Vaishampayan, Shailesh Arvind <svaishampa...@inautix.co.in>:
>       ClientAction extends ActionSupport throws Exception{
>
>          ....
>
>         try{
>
>             clientService.searchClient();
>
>         }catch(InvalidClientSearchCriteriaException e){
>
>               addActionMessage("Invlid Search Criteria");
>
>         }
>
>         ...
>
> And similar code in every action class. However i dont want to pollute my 
> action classes with try catch blocks. Instead it would be much better if i 
> can write on try catch block at one place and catch all the exceptions there 
> as BusinessExceptions and create messages /errors from embedded 
> messages/errors in those exceptions. One approach i could think of was to use 
> interceptor or preresult listener. But I cannot use interceptor like below 
> which catches BusinessExceptions thrown from action classes...
>
>     ExceptionInterceptor extends AbstractInterceptor(ActionInvocation 
> ivocation,...){
>
>           try{
>
>                     invocation.invoke();
>
>           }catch(Exception e){
>
>               if(e instanceof BusinessException){
>
>                    ActionSupport as = (ActionSupport)invocation.getAction();
>
>                    String message = extractMessagefromException()//--custom 
> method to extract message embedded in exception.
>
>                as.addActionMessages(message);
>
>       //-- above will not work result has already been rendered right? and 
> hence it wouldn't matter if i add action messages now.
>
>            }
>
>          }
>
>    }
>
> Second approach of using pre-result listener is to add action messages just 
> like above in pre-result listener's method, as result is yet to be rendered 
> and I can safely change that. However I am not sure if pre-result listener 
> will ever execute, if exception is thrown in action ? And even if it does, 
> how i can get the exception object thrown by the action ?

Result wasn't rendered yet but you must return some result from the
interceptor, e.g.:

try{
    return invocation.invoke();
} catch (Exception) {
    // handle BusinessException
    return "success";
}

It just an example, you must adjust it to your needs.


Regards
-- 
Ɓukasz
+ 48 606 323 122 http://www.lenart.org.pl/

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

Reply via email to