Check for a column in the DataReader OR do not disable the debugger for specific exceptions

I have a code that looks like this:

  //System.Data.IDataRecord dr
  try
  {
       Consolidated = Utility.NullConvert.ToBool(dr[Constants.Data.Columns.cConsolidated], false);
  }
  catch (IndexOutOfRangeException) { } //swallow

I do not know if a consolidated column will be present in the datareader, so I do this for verification. It works great (a bit hacky).

When I attach a debugger, it breaks into this when it throws an exception. Extremely annoying.

Is there a better way to write this code; or is there some kind of Visual Studio method telling it to ignore the exception and not interrupt (but only right here, and not everywhere).

+3
source share
3 answers

, GetSchemaTable() datareader , , .

, .

+2

GetOrdinal() , ( ). , >=0. ( , ).

, . , .

+2

:

reader.GetSchemaTable().Columns.Contains("Your_Column")

.

If reader.GetSchemaTable().Columns.Contains("ContactID") Then
   ' Do something
End If
-1
source

All Articles