Announcement Announcement Module
No announcement yet.
AOP Exception handling Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • vincentinc
    started a topic AOP Exception handling

    AOP Exception handling

    I'm new to AOP. I got a design dilemma. I have a method that throw IOException.

    public void somemethod() throws IOException.

    At the same time I wanted to apply MethodInterceptor to this method with throw FileNotFoundException. This is my problem, at the class that call somemethod expect IOException, however after applying MethodInterceptor which throw FileNotFoundException the class have to catch FileNotFoundException as well. At compile time the compiler will complain. Is this a common thing in AOP? Is there a better way of doing this?

  • Andreas Senft
    The point is, as you already found out, that calling code does not know about the called method being proxied. So it cannot (and should not) make any assumptions about this fact. Undeclared exceptions originating in the interceptor should therefore be avoided if possible. If not possible, they should be considered as unrecoverable failure.
    Besides that, you should never throw undeclared checked exceptions but use runtime exceptions instead.

    That said, in your case I see no problem since FileNotFoundException is actually a subclass of IOException (hence is not treated as undeclared).


    Leave a comment: