Avoiding exception messages from the first accident when the exception is safely handled

The next bit of code catches an EOS exception

using (var reader = new BinaryReader(httpRequestBodyStream)) { try { while (true) { bodyByteList.Add(reader.ReadByte()); } } catch (EndOfStreamException) { } } 

So why am I still getting exceptions from first chance in my console?

The first exception of type "System.IO.EndOfStreamException" exception occurred in mscorlib.dll

Is there a way to hide these exceptional random exception messages?

+73
c # exception
Sep 12 '08 at 5:48
source share
9 answers

The “first chance” exception point is that you see them in front of the handler so that you can stop at them while debugging at the time of throwing. The second chance exception is one that does not have a matching handler. Sometimes you want to catch the exceptions of the "first chance", because it is important to see what happens when he throws, even if someone catches him.

There is nothing to worry about. This is normal behavior.

+77
Sep 12 '08 at 5:56
source share

To avoid viewing messages, right-click on the output window and clear the "Exceptional Messages" checkbox.

However, seeing them can be enjoyable if you are interested in knowing when exceptions are thrown, without setting breakpoints or reconfiguring the debugger.

+188
Sep 13 '08 at 18:48
source share

1) In Visual Studio, you can change the settings for how the debugger handles (interrupts) exceptions.

Go to Debug> Exceptions. (Note that this may not be on your menu depending on the setting of the Visual Studio environment. If you do not just add it to your menu in the "Customize" menu.)

There you will get a dialog with exceptions and when to break them.

In the line "General runtime exceptions", you can unselect (which should stop bothering you with exceptions from the first chance), and you can also unselect User-unhandeled (which I would not recommend) if you want.

2) The message you receive should not be in the console, but should appear in the "Exit" window of Visual Studio. If so, then I did not find a way to remove it, but it does not appear if you run the application without Visual Studio.

Hope this helps.

+19
Sep 12 '08 at 6:06
source share

Unlike Java, .NET exceptions are quite expensive in terms of processing power, and processed exceptions should be avoided in a normal and successful execution path.

You will not only avoid clutter in the console window, but also improve your performance and make performance counters such as .NET CLR Exceptions more meaningful.

In this example, you would use

 while (reader.PeekChar() != -1) { bodyByteList.Add(reader.ReadByte()); } 
+10
Sep 12 '08 at 6:32
source share

I had this problem and could not figure out where the exception was thrown. So my solution was to let Visual Studio stop this exception.

  • Go to the Debug / Exceptions section
  • Expand the Common Language Runtime Exceptions tree.
  • Expand the System branch.
  • Scroll down to “NullReferenceException” and check “drop” and uncheck “processed by user”.
  • Debug your project.
+7
Oct 26 '12 at 11:32
source share

If you want more control over these messages, you can add a handler:

 Friend Sub AddTheHandler() AddHandler AppDomain.CurrentDomain.FirstChanceException, AddressOf FirstChanceExceptionHandler End Sub <Conditional("DEBUG")> Friend Sub FirstChanceExceptionHandler( source As Object, e As Runtime.ExceptionServices.FirstChanceExceptionEventArgs) ' Process first chance exception End Sub 

This allows you to silence them, as indicated in other comments, but still ensures that you can know them. I find it good to see how much I really throw if I register a message and timestamp in a text file.

+4
Apr 18 '14 at 18:16
source share

In fact, if you have many exceptions per second, you should achieve better performance by checking the reader.EndOfStream value. Printing these exception messages is incredibly slow, and hiding them in the visual studio will not speed anything up.

+2
May 09 '10 at 21:49
source share

in VB.NET:

 <DebuggerHidden()> _ Public Function Write(ByVal Text As String) As Boolean ... 
-one
07 Aug '09 at 21:23
source share

I think the thread throws this exception, so your attempt is limited to catch it.

Add a few more attempts to catch combos around different areas until you catch them where they are really thrown, but it seems to happen either outside of our use, since the stream object is not created in the use area.

-four
Sep 12 '08 at 5:50
source share



All Articles