G
Guest
Is it a bug or by design that the RowChanged event swallows all exceptions
which are thrown on event handlers? I would have expected an Unhandled
Exception. The following code reproduces this behaviour.
class DataTableException
{
[STAThread]
static void Main(string[] args)
{
// Create table
DataTable table = new DataTable();
// Create and add column
DataColumn column = table.Columns.Add();
column.DataType = typeof(string);
// Add a row
table.Rows.Add(new object[]{"Test"});
// Adding Event Handler
table.RowChanged += new
DataRowChangeEventHandler(Table_DataRowChanged);
// Changing Row
table.Rows[0][0] = "Changing";
Console.WriteLine("Finished");
}
private static void Table_DataRowChanged(object sender,
DataRowChangeEventArgs e)
{
Console.WriteLine("Row Changed : Action " + e.Action);
Console.WriteLine("Throwing Exception");
// Throwing exception
throw new Exception("This is an exception.");
}
I have used .NET Reflector to look at the RaiseRowChanged method on the
DataTable and found the following code for rows being updated. (V1.1)
try
{
this.OnRowChanged(e);
}
catch (Exception exception1)
{
ExceptionBuilder.Trace(exception1);
}
which are thrown on event handlers? I would have expected an Unhandled
Exception. The following code reproduces this behaviour.
class DataTableException
{
[STAThread]
static void Main(string[] args)
{
// Create table
DataTable table = new DataTable();
// Create and add column
DataColumn column = table.Columns.Add();
column.DataType = typeof(string);
// Add a row
table.Rows.Add(new object[]{"Test"});
// Adding Event Handler
table.RowChanged += new
DataRowChangeEventHandler(Table_DataRowChanged);
// Changing Row
table.Rows[0][0] = "Changing";
Console.WriteLine("Finished");
}
private static void Table_DataRowChanged(object sender,
DataRowChangeEventArgs e)
{
Console.WriteLine("Row Changed : Action " + e.Action);
Console.WriteLine("Throwing Exception");
// Throwing exception
throw new Exception("This is an exception.");
}
I have used .NET Reflector to look at the RaiseRowChanged method on the
DataTable and found the following code for rows being updated. (V1.1)
try
{
this.OnRowChanged(e);
}
catch (Exception exception1)
{
ExceptionBuilder.Trace(exception1);
}