0

I wanted to help out this guy who had a catch(Exception) clause in his code. Bad practice. Should catch specific exceptions. OK, so what are they?

I consulted the documentation for the only method he was calling, OdbcAdapter.Fill(DataSet), and found the input/output list, which usually lists all the possible exceptions. None listed. Does it ever throw any?

Then I found this documentation, which suggests that Fill doesn't throw exceptions, it swallows them and instead raises events.

But then I found this.

And this.

Does OdbcDataAdapter.Fill(DataSet) throw exceptions or not? What exceptions? Does it raise events or not?

Community
  • 1
  • 1
John Wu
  • 50,556
  • 8
  • 44
  • 80

1 Answers1

0

Its may help u.

The following code example adds an event handler for the FillError event of the DataAdapter. In the FillError event code, the example determines if there is the potential for precision loss, providing the opportunity to respond to the exception.

 adapter.FillError += new FillErrorEventHandler(FillError);
 DataSet dataSet = new DataSet();
 adapter.Fill(dataSet, "ThisTable");
 protected static void FillError(object sender, FillErrorEventArgs args)
 {
     if (args.Errors.GetType() == typeof(System.OverflowException))
           {
               // Code to handle precision loss.
               //Add a row to table using the values from the first two            
               columns.
               DataRow myRow = args.DataTable.Rows.Add(new object[]
               {args.Values[0], args.Values[1], DBNull.Value});
               //Set the RowError containing the value for the third column.
                args.RowError = 
               "OverflowException Encountered. Value from data source: " +
                args.Values[2];
                args.Continue = true;
            }
  }

Reference : https://msdn.microsoft.com/en-us/library/6d1wk41s(v=vs.110).aspx

Karthikeyan
  • 333
  • 5
  • 17