Ico
05-04-2007, 12:43 PM
Hi,
I am trying to implement a ThrowsAdvice and am getting some strange behaviour that I'm not sure is correct. I have wired up my ThrowsAdvice and it is being triggered correctly, but the problem I am having is that when an exception is thrown from within any of my AfterThrowing methods, only the baseException gets thrown. I have had a look in the Spring code and believe the following method inside ThrowsAdviceInterceptor is responsible.
private void InvokeHandlerMethod(
IMethodInvocation invocation, Exception triggeringException, MethodInfo handlerMethod)
{
object[] handlerArgs;
if (handlerMethod.GetParameters().Length == 1)
{
handlerArgs = new object[] {triggeringException};
}
else
{
handlerArgs = new object[] {invocation.Method, invocation.Arguments, invocation.This, triggeringException};
}
try
{
handlerMethod.Invoke(this.throwsAdvice, handlerArgs);
}
catch (TargetInvocationException ex)
{
throw ex.GetBaseException();
}
}
So finally to my question, inside the catch(TargetInvocationException ex) the baseException is being thrown, this seems wrong to me, either the whole exception should be thrown or just the innerexception thereby discarding the targetinvocationexception. Is this a bug, or are my expectations of how ThrowsAdvice work just plain wrong.
Any guidence on this would be much appreciated
thanks
Jim
I am trying to implement a ThrowsAdvice and am getting some strange behaviour that I'm not sure is correct. I have wired up my ThrowsAdvice and it is being triggered correctly, but the problem I am having is that when an exception is thrown from within any of my AfterThrowing methods, only the baseException gets thrown. I have had a look in the Spring code and believe the following method inside ThrowsAdviceInterceptor is responsible.
private void InvokeHandlerMethod(
IMethodInvocation invocation, Exception triggeringException, MethodInfo handlerMethod)
{
object[] handlerArgs;
if (handlerMethod.GetParameters().Length == 1)
{
handlerArgs = new object[] {triggeringException};
}
else
{
handlerArgs = new object[] {invocation.Method, invocation.Arguments, invocation.This, triggeringException};
}
try
{
handlerMethod.Invoke(this.throwsAdvice, handlerArgs);
}
catch (TargetInvocationException ex)
{
throw ex.GetBaseException();
}
}
So finally to my question, inside the catch(TargetInvocationException ex) the baseException is being thrown, this seems wrong to me, either the whole exception should be thrown or just the innerexception thereby discarding the targetinvocationexception. Is this a bug, or are my expectations of how ThrowsAdvice work just plain wrong.
Any guidence on this would be much appreciated
thanks
Jim