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.

Leave a Comment

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