Exception thrown in RowChanged handler is not propagated

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a test bed of code that I am using to isolate this situation. There is a bit of code involved, so I'll try posting a narrative description first.
1) I have a strongly typed dataset called OrdersDS
2) I have inherited from this dataset to extend it - the new class is called OrdersDSExt
3) In the constructor of OrdersDSExt, I add an event handler to the ORDERS datatable for the RowChanged event
4) In the event handler, I check the value of the ORDERAMT column to be sure it is >=0. If it is < 0, I throw an exception.

Here's the problem: the exception occurs BUT it is not propagated up the stack so the "naughty" code has no idea a problem has occurred. What am I missing here?
 
Hi Doug,

Yes, you are correct. The exception is not propagated.
You should place your code in RowChanging event - if you throw an exception
there no change will occur.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Doug Clutter said:
I have a test bed of code that I am using to isolate this situation.
There is a bit of code involved, so I'll try posting a narrative description
first.
1) I have a strongly typed dataset called OrdersDS
2) I have inherited from this dataset to extend it - the new class is called OrdersDSExt
3) In the constructor of OrdersDSExt, I add an event handler to the ORDERS
datatable for the RowChanged event
4) In the event handler, I check the value of the ORDERAMT column to be
sure it is >=0. If it is < 0, I throw an exception.
Here's the problem: the exception occurs BUT it is not propagated up the
stack so the "naughty" code has no idea a problem has occurred. What am I
missing here?
 
Thanks Miha. The RowChanging event works fine...however, I am a little troubled that something as fundamental as throwing an exception would be "ignored"....and silently ignored to boot. Does anyone share my concern here?
 
Hi Doug,

I share your concern. We've few cases where we are eating exceptions which
will just mask the errors. Exceptions should be propagated all the way.
We'll be fixing issues related with eating exceptions.

Thanks,
-Ravi

Doug Clutter said:
Thanks Miha. The RowChanging event works fine...however, I am a little
troubled that something as fundamental as throwing an exception would be
"ignored"....and silently ignored to boot. Does anyone share my concern
here?
 
Back
Top