C # exception handling doesn't behave as I expect - why?

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 the release and push a lot of data into the service, VS2010 stops at the line "writeDataToChannel" with the exception of a TimeoutException. Should my catch block catch the exception and just print it when the timeout happens?

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

This is not a namespace problem, in both cases it is a System.TimeoutException exception.

+4
source share
4 answers

It seems to me that you have Visual Studio to dwell on the thrown exception. Go to the Debug->Exceptions menu Debug->Exceptions and see what your CLR Exceptions settings are. To get the behavior that you describe, you do not want to dwell on caught or uncaught exceptions.

Also, do not run it under the debugger.

+7
source

You probably need to tell VS so that it doesn't crash every exception thrown in the exception dialog (ctrl + alt + e and disable CLR exceptions)

+5
source

As already mentioned, this happens when you debug a project (by pressing F5 or pressing the green triangle button ">").

To start without debugging, enter CTRL + F5 or click the "Start without debugging" button or button.

You don't have to remove this option to dwell on exceptions, as others have mentioned, but go ahead and do it if it gets annoying.

+2
source

You will need to quit to catch something in your attempt / catch

  throw 
-eight
source

Source: https://habr.com/ru/post/1385391/


All Articles