Why is TargetInvocationException treated as uncaught by the IDE?
- by Jason Coyne
I have some code that is using reflection to pull property values from an object. In some cases the properties may throw exceptions, because they have null references etc.
try
{
child.Target = propertyInfo.GetValue(target, null);
}
catch (TargetInvocationException ex)
{
child.Target = ex.InnerException.Message;
}
catch (Exception ex)
{
child.Target = ex.Message;
}
Ultimately the code works correctly, however when I am running under the debugger :
When the property throws an exception, the IDE drops into the debugger as if the exception was uncaught. If I just hit run, the program flows through and the exception comes out as a TargetInvocationException with the real exception in the InnerException property.
How can I stop this from happening?