4

I have the following C# code:

try { response = this.writeDataToChannel(writeRequest); if (response.Failures != null) { Console.WriteLine(response.Failures.First().cause); } } catch (TimeoutException te) { Console.Error.WriteLine(te.Message); } 

When I run this code in release and push a lot of data to the service, VS2010 stops on the "writeDataToChannel" line with a TimeoutException. Shouldn't my catch block catch the exception and just print it when the timeout happens?

The "writeDataToChannel" code was generated from a WSDL, the writes always work until I push tons of data to the webservice, so I don't think there is a problem with my request.

It is not a namespace issue, in both cases it is a System.TimeoutException.

4
  • Are you debugging the project? Commented Dec 8, 2011 at 17:48
  • 3
    You're talking about the debugger. Of course running code in the debugger works differently! The debugger is giving you a chance to look at the exception. Press F5 and your catch block will be reached. Commented Dec 8, 2011 at 17:48
  • Is this run within the context of a web service? Commented Dec 8, 2011 at 17:49
  • I didn't know the behavior @JohnSaunders discussed. Thanks. Commented Dec 8, 2011 at 17:58

4 Answers 4

7

It sounds to me like you have Visual Studio set to stop on a thrown exception. Go to the menu item Debug->Exceptions and see what your CLR Exceptions settings are. To get the behavior that you're describing, you don't want to stop on caught or uncaught exceptions.

Alternatively, don't run it under the debugger.

Sign up to request clarification or add additional context in comments.

1 Comment

I didn't know about those settings, you (and everyone else that answered with this answer) are right.
5

You probably need to tell VS to not break on each thrown exception in the exceptions dialog (ctrl + alt + e and uncheck CLR exceptions)

Comments

2

As others have mentioned, this happens when you are debugging the project (by hitting F5, or clicking the green triangle button ">").

To run without debugging, type CTRL + F5, or click the "Start without debugging" menu choice or button.

You don't necessarily need to remove the option to stop on exceptions like others have mentioned, but go ahead and do so if it becomes annoying.

Comments

-8

You will need to throw in order to catch something in your try/catch

 throw 

2 Comments

You should delete your answer before you loose more rep!
He doesn't throw the exception, an underlying class or library is throwing the exception.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.