PDA

View Full Version : IThrowsAdvice and VS2005: strange behaviour


Diego
08-14-2007, 05:39 PM
Hello again. I'm testing IThrowsAdvice with a very simple application and I've found a strange behaviour of VS2005 in debug mode: suppose you have this simple and useless example


public interface IA
{
void m1();
void m2();
}

public class A : IA
{
public void m1()
{
try
{
IApplicationContext ctx = ContextRegistry.GetContext();
IA a = (A) ctx.GetObject( "A" );
a.m2();
}
catch( Exception exc )
{
Console.Out.WriteLine( "EXC: " + exc.Message );
throw exc;
}
}

public void m2()
{
try
{
string s = null;
s.Contains( "ARGH" );
}
catch( Exception exc )
{
Console.Out.WriteLine( "EXC: " + exc.Message );
throw exc;
}
}
}
and this is the calling code:


try
{
IApplicationContext ctx = ContextRegistry.GetContext();
IA a = (A) ctx.GetObject( "A" );
a.m1();
}
catch( Exception exc )
{
Console.Out.WriteLine( "EXC: " + exc.Message );
}
With the class A proxied and two advices: one implementing IMethodInterceptor and the other implementing IThrowsAdvice. Say that in the first one I call only Proceed() on the invocation object (without try/catch block, also if I've tried with try/catch) and in the second I output only something on the Console.Out. Well, if I'm in debug mode with Visual Studio 2005, on every "throw exc;", it stops complaining about an unhandled exception on that line of code. Instead, if I run the same application without VS2005, it performs in the expected way, because the exception is handled! I've made the same test without AOP and it works fine in debug mode and not, so I think there is something that Spring.net introduce.

Is this normal ? Or I forgot to include some try/catch block elsewhere ?

Thanks for the help.

Mark Pollack
08-17-2007, 04:02 PM
Hi Deigo,

I think the approach listed in this other post (http://forum.springframework.net/showpost.php?p=8476&postcount=12) maybe more along the lines of what you are trying to achive. Let me know.

Cheers,
Mark

Diego
08-17-2007, 05:58 PM
I think the approach listed in this other post (http://forum.springframework.net/showpost.php?p=8476&postcount=12) maybe more along the lines of what you are trying to achive. Let me know.


Yes, it resolves one problem, but not the unhandled exceptions problem. Very strange indeed.

I attach a simple VS2005 solution if someone wants to try it.

Thanks for the help.