Announcement Announcement Module
Collapse
No announcement yet.
AfterThrowingAdvice - trap and return something else? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AfterThrowingAdvice - trap and return something else?

    If a method throws an exception and this is intercepted by an after-throwing advice can this trap the exception and instead propagate a method return response as per the original method?

    e.g.
    original method that can throw a IOException lets say:
    public
    Code:
    String getName() throws IOException {..}
    Advice:
    Code:
    public String processException(IOException e) {
                  LOG.exception (e);
                  return "NONAME";
               }
    If that is not possible can I throw a new type of exception?
    Last edited by pbarry30; Dec 15th, 2011, 02:16 PM.

  • #2
    I think the direct answer is no to the return type but yes to throwing a new type of exception.
    In AspectJAfterThrowingAdvice in the invoke method in the catch block, anything returned is ignored and the original exception is rethrown.

    Comment


    • #3
      Use Around advice. In your advice code, wrap the pjp.proceed() call inside a try catch block, catching the type of exception that you expect. In the catch block, do logging stuff and then return what you want to return in case of exception.

      With AfterThrowing advice what you want to do is not possible.

      Comment

      Working...
      X