Feb 22nd, 2006, 11:27 PM
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?
Feb 23rd, 2006, 01:16 AM
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).