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);
> }