PC Review


Reply
Thread Tools Rate Thread

DataTable RowChanged event swallowing exceptions?

 
 
=?Utf-8?B?RGF2aWQgUGFkYnVyeQ==?=
Guest
Posts: n/a
 
      18th Aug 2005
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);
}
 
Reply With Quote
 
 
 
 
Kawarjit Bedi [MSFT]
Guest
Posts: n/a
 
      18th Aug 2005
DataTable's RowChangedEvent catches all exceptions that may get raised in
the associated EventHandler. All User exceptions are suppressed but System
exceptions like StackOverflow, OutOfMemory, ThreadAbort, NullReference,
AcessViolation are re-thrown.

This behavior is by design.

We recommend that data validation and other business logic be executed in
RowChangingEvent and if any user exceptions needs to be raised in the
EventHandler, it will ripple up.


Thanks,
Kawarjit Bedi [MSFT]

This posting is provided "AS IS" with no warranties, and confers no rights.

"David Padbury" <David (E-Mail Removed)> wrote in message
news:EB77C15C-0CFD-4674-8E4D-(E-Mail Removed)...
> 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);
> }



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving from a DataGrid on a DataTable.RowChanged Event =?Utf-8?B?VGhvbWFzIENvcmNvcmFu?= Microsoft ADO .NET 0 25th Dec 2006 10:32 PM
DataTable & RowChanged Event =?Utf-8?B?Y2hyaXNjQGhhY2tldHRwdWJsaXNoaW5nLmNvbQ== Microsoft ADO .NET 5 24th Nov 2004 04:58 AM
DataTable.RowChanged Event not picking up new rows. Mike Edenfield Microsoft ADO .NET 0 1st Nov 2004 02:38 PM
new problem hooking up to datatable rowchanged event Bernie Yaeger Microsoft ADO .NET 6 30th Nov 2003 06:58 PM
trouble hooking up datatable rowchanged event - Miha, help! Bernie Yaeger Microsoft ADO .NET 1 28th Nov 2003 06:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:19 PM.