Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] ExceptionHandling

> But the problem is that the methods which throw the ServletException 
> have a different number of parameters and the types of the parameters

This shouldn't be a problem. All proceed() needs is that you pass
along the same number and type of argument as the collected context.
So even if the method captured have different number and type of 
parameters, since your advice won't be collecting all of them, 
you should be fine.

For example, you may do something like:

pointcut operations(HttpServletResponse response)
    : (execution(* HttpServlet+.do*(*, HttpServletResponse) throws 
       ServletException  && args(*, response))
      || (execution(* foo(int, float, HttpServletResponse, Bar)
          throws ServletException  && args(int, float, response, Bar))
      || ... ;

Then (and this answers your other part of the question):
Object around(HttpServletResponse response) 
      : operations(response) {
    try {
        return proceed(response);
    } catch (ServletException  ex) {
        printANiceMessage(ex);
        // rethrow? log? etc.
    }
    return null;
}

-Ramnivas

--- Steffen Euch <steffen.euch@xxxxxxxxx> wrote:
> Hi!
> 
> I'm trying to handle all ServletExceptions that my Servlets throw
> with 
> one aspect in a common way.
> 
> In my opinion the best way would be to use an around advice like in 
> Listing 8.19 in the "AspectJ in Action" book:
> 
> Object around() : operations() {
>    try {
>      proceed();
>    }
>    catch ...
> }
> 
> But the problem is that the methods which throw the ServletException 
> have a different number of parameters and the types of the parameters
> 
> differ, too. I can't capture all this methods with one
> proceed()-call, 
> right?
> 
> 
> Another idea ist to use this advice:
> 
> after() throwing(javax.servlet.ServletException ex) ...
> 
> But now I have the problem that the exception is already thrown and I
> 
> can't catch it anymore, right?
> 
> 
> Another problem is the common handling of the exceptions. I need the 
> HttpServletResponse object to display the user a nice error message 
> instead of the exception stack trace, but I have found no way to
> access 
> it in the advice.
> 
> Thanks for your help in advance!
> 
> Steffen
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users



	
		
__________________________________
Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25ยข
http://photos.yahoo.com/ph/print_splash


Back to the top