I am using Spring's AOP feature. I have class called
class UserService {
public User insertUserService(User user) throws PersistenceLayerException {
System.out.println("UserServiceImpl_Two called: insertUserService method");
if (user.id == 1)
throw new PersistenceLayerException();
return null;
}
}
Now, the calls to this method insertUserService
are intercepted by an interceptor which does some validation. This validation interceptor throws a checked exception called BusinessException
. Now, when this exception is thrown, Java throws an UndeclaredThrowableException
because BusinessExcepetion
is not declared in the throws of insertUserService
. Is there a way to get around this UndeclaredThrowableException
without having to declare the BusinessException
in the throws clause.
The reason being there in nothing in insertUserService
itself that throws a BusinessException
, so its appear there should be way around.