ObjectDataSource and Exception handling

N

nunya5200-bidness

I hope someone may have some insight to this issue...

I would like to know how to properly implement exception handling using
the ObjectDataSource control.

Specfically, I am doing an insert using an object that calls a web
service to accomplish this. The service returns a message to the
Insert method that indicates that the insert can't be accomplished
because it is trying to insert a duplicate key value. So, I simply
want to raise a custom exception ("NotUniqueException"). All this
works great, however, I can't for the life of me figure out where to
catch this exception.

The ObjectDataSource Control Inserting event takes place before the
method is called and the Inserted event after the fact. The button on
the FormView has a command of "Insert" so the insert method is "just
called from somewhere"...

Any ideas?

Thanks.
charlie
 
B

Brock Allen

When there is an exception in your class' Update method and you don't catch
it (meaning it's unhandled), the ODS catches it and presents it in the Updated
event of the ODS. The ObjectDataSourceStatusEventArgs passed to the Updated
event has an Exception property to let you know if an exception was thrown.
If you then set ObjectDataSourceStatusEventArgs.ExceptionHandled to true,
then nothing else special happens. If you leave ObjectDataSourceStatusEventArgs.ExceptionHandled
= false, then you'll see the normal unhandled exception behavior in ASP.NET.

So, in short, handle the Updated event, check the Exception object, show
your user the error somehow, and set ExceptionHandled = true.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top