views:

28

answers:

1

I've encountered some very strange behaviour when debugging in VS 2010 with a WCF Service. Here's a snippet:

public MapFileInfo[] ListFiles(string user, string pass)
{
   return s.ListFiles(user, pass);
}

I want an exception to bubble up to the main application if authentication fails. However, what actually happens during debug mode is that it recalls s.ListFiles(user, pass). So to further test my theory that VS is doing something fishy I just did the following:

try
{
   return s.ListFiles(user, pass);
}
catch (SoapHeaderException e)
{
   throw e;
}

Lo and behold, throw e gets called over, and over, and over when I step into (F8) instead of throwing it to the calling statement through the call stack.

Anyone experienced this weird behaviour before? I can't debug through my app because of it. Additionally, I can step through the service code which obviously throws an exception and returns to the calling statement (s.ListFiles that is) so I know that's happening.

A: 

I think this is desired behavior. If no Exception-Handler is used, VS will stop at the throwing call and wait for your action, if you resume debugging, VS will try to call the erroneous function again (after all, you could have changed something to make it go away in the meantime).

So, it seems like that you've no Exception-Handler in the calling function of ListFiles.

If you want a generic error handler throughout your whole application, add handlers to the events AppDomain.CurrentDomain.UnhandledException and Application.ThreadException.

Bobby
Indeed I did end up catching all exceptions, but this did strike me as particularly odd regardless. I would've expected an exception to be thrown.
Kezzer
@Kezzer: Technically, it was thrown. That would have been the point where the user receives the "An Unhandled Exception occured" window, but the debugger seems to stop right there and tries to execute the faulty code over and over.
Bobby