Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding first chance exception messages when the exception is safely handled

Tags:

c#

.net

exception

The following bit of code catches the EOS Exception

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

So why do I still receive first-chance exceptions in my console?

A first chance exception of type 'System.IO.EndOfStreamException' occurred in mscorlib.dll

Is there a way to hide these first chance exception messages?

like image 449
CVertex Avatar asked Sep 12 '08 05:09

CVertex


People also ask

What is first chance exception?

When an application is being debugged, the debugger gets notified whenever an exception is encountered. At this point, the application is suspended and the debugger decides how to handle the exception. The first pass through this mechanism is called a "first chance" exception.

What is Second Chance exception?

If the application does not handle the exception, the debugger is re-notified. This is known as a "second chance" exception. The debugger again suspends the application and determines how to handle this exception.


2 Answers

To avoid seeing the messages, right-click on the output window and uncheck "Exception Messages".

However, seeing them happen might be nice, if you're interested in knowing when exceptions are thrown without setting breakpoints and reconfiguring the debugger.

like image 101
André Chalella Avatar answered Sep 24 '22 00:09

André Chalella


The point of "first-chance" exceptions is that you're seeing them pre-handler so that you can stop on them during debugging at the point of throwing. A "second-chance" exception is one that has no appropriate handler. Sometimes you want to catch "first-chance" exceptions because it's important to see what's happening when it's being thrown, even if someone is catching it.

There's nothing to be concerned with. This is normal behavior.

like image 23
Brad Wilson Avatar answered Sep 22 '22 00:09

Brad Wilson