What Are First Chance Exceptions?

It is normal for a lot of exceptions to be thrown, caught, and then ignored. The internals of the .NET Framework even throws some exceptions that are discarded. One of the features of C# is something called first chance exceptions. It enables you to get visibility into every single .NET Exception being thrown.

It is very common for code like this below to be used within applications. This code can throw thousands of exceptions a minute and nobody would ever know it. This code is from another blog post about an app that had serious performance problems due to bad exception handling. Exceptions will occur if the reader is null, columnName is null, columnName does not exist in the results, the value for the column was null, or if the value was not a proper DateTime. It is a minefield.


public DateTime? GetDate(SqlDataReader reader, string columnName)
{
   DateTime? value = null;
   try
   {
      value = DateTime.Parse(reader[columnName].ToString());
   }
   catch
   {
   }
   return value;
}