org.springframework.aop.framework.adapter
public class: ThrowsAdviceInterceptor [javadoc |
source]
java.lang.Object
org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor
All Implemented Interfaces:
org.aopalliance.intercept.MethodInterceptor, AfterAdvice
Interceptor to wrap an after-throwing advice.
The signatures on handler methods on the ThrowsAdvice
implementation method argument must be of the form:
void afterThrowing([Method, args, target], ThrowableSubclass);
Only the last argument is required.
Some examples of valid methods would be:
public void afterThrowing(Exception ex)
public void afterThrowing(RemoteException)
public void afterThrowing(Method method, Object[] args, Object target, Exception ex)
public void afterThrowing(Method method, Object[] args, Object target, ServletException ex)
This is a framework class that need not be used directly by Spring users.
- author:
Rod - Johnson
- author:
Juergen - Hoeller
| Constructor: |
public ThrowsAdviceInterceptor(Object throwsAdvice) {
Assert.notNull(throwsAdvice, "Advice must not be null");
this.throwsAdvice = throwsAdvice;
Method[] methods = throwsAdvice.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName().equals(AFTER_THROWING) &&
//m.getReturnType() == null &&
(method.getParameterTypes().length == 1 || method.getParameterTypes().length == 4) &&
Throwable.class.isAssignableFrom(method.getParameterTypes()[method.getParameterTypes().length - 1])
) {
// Have an exception handler
this.exceptionHandlerMap.put(method.getParameterTypes()[method.getParameterTypes().length - 1], method);
if (logger.isDebugEnabled()) {
logger.debug("Found exception handler method: " + method);
}
}
}
if (this.exceptionHandlerMap.isEmpty()) {
throw new IllegalArgumentException(
"At least one handler method must be found in class [" + throwsAdvice.getClass() + "]");
}
}
Create a new ThrowsAdviceInterceptor for the given ThrowsAdvice. |
| Method from org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor Detail: |
public int getHandlerMethodCount() {
return this.exceptionHandlerMap.size();
}
|
public Object invoke(MethodInvocation mi) throws Throwable {
try {
return mi.proceed();
}
catch (Throwable ex) {
Method handlerMethod = getExceptionHandler(ex);
if (handlerMethod != null) {
invokeHandlerMethod(mi, ex, handlerMethod);
}
throw ex;
}
}
|