Wednesday, January 17, 2007

Drag 'N Drop is great, but what about exception handling

So, you think the new Visual Studio 2005 and ASP.Net are pretty nice. You get rapid development from drag 'n drop objects like ObjectDataSources, GridView, etc. Then the dreaded exception occurs in your business object. Where does that appear in all this? How do you get to that exception? Believe it or not, Microsoft did it right. They have an event called ObjectDataSource Selected event that you can tap into just like you would any other event.

 

To check for an exception you would do something like this:

 

protected void ObjectDataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs e)

        {

           

 

            if (e.Exception != null)

            {

 

               

                if (e.Exception.InnerException != null)

                {

                        if (e.Exception.InnerException is IOException)

                        {    

                              // do something with the exception.  

                              e.ExceptionHandled = true; // so it doesn't keep bubbling up

                        {

                }

 

            }

 

        }

 

No comments: