Catching the exception from the ObjectDataSource Inserted Event

One thing I was puzzled over today was that I could see the Exception property of the ObjectDataSourceStatusEventArgs but I could not seem to cast it into the Exception I was expecting.  After a little mooching around, and debugging the actual type of the Exception property I found that it is actually of the type:

System.Reflection.TargetInvocationException

 

Which in turns holds a property called InnerException.  This is the Exception property that I needed to cast. 

        protected void ArticleDataSourceInserted(object sender, ObjectDataSourceStatusEventArgs e)
        {
            if (e.Exception != null)
            {
                System.Reflection.TargetInvocationException exc= (System.Reflection.TargetInvocationException)e.Exception;

}

}

Oh and also, make sure that you indicate that the Exception has been handled, assuming that is has ofcourse.  This is a boolean property of the ObjectDataSourceStatusEventArgs.

e.ExceptionHandled = true;

 

Cheers,

 

Andrew

Published Monday, November 17, 2008 3:59 PM by REA_ANDREW

Comments

# re: Catching the exception from the ObjectDataSource Inserted Event

Tuesday, September 08, 2009 8:52 AM by Robson Previato

Obrigado pela dica.

# re: Catching the exception from the ObjectDataSource Inserted Event

Saturday, March 27, 2010 1:41 AM by Calida

Hey. I'm moving, but don't worry! [Someone once] told me we're all on the same planet, so I'll be okay! Help me! Looking for sites on: Rachel ashwell baby bedding. I found only this - <a href="baby-bedding.net/">white baby bedding</a>. Some of this dollar is assumed from one justice to the many, bedding. Bedding, acquire snorkelling museums of people and trademarks. THX :-), Calida from Cuba.

# re: Catching the exception from the ObjectDataSource Inserted Event

Saturday, June 12, 2010 7:29 PM by !S!WCRTESTINPUT000001!E!

!S!WCRTESTTEXTAREA000003!E!

Leave a Comment

(required) 
(required) 
(optional)
(required)