c# - Why is TargetInvocationException treated as uncaught by the IDE? -
i have code using reflection pull property values object. in cases properties may throw exceptions, because have null references, etc.
object result; try { result = propertyinfo.getvalue(target, null); } catch (targetinvocationexception ex) { result = ex.innerexception.message; } catch (exception ex) { result = ex.message; }
ultimately code works correctly, when running under debugger:
when property throws exception, ide drops debugger if exception uncaught. if hit run, program flows through , exception comes out targetinvocationexception real exception in innerexception property.
how can stop happening?
this seems "by design". happens have menu tools → options → debugging → general → enable code enabled.
as how to: break on user-unhandled exceptions states:
the debug → exceptions dialog shows additional column (break when exception user-unhandled) when "enable code" on.
essentially means whenever exception leaving boundary of code (and in case, falls through down .net framework reflection code), visual studio breaks because thinks exception has left user code. doesn't know return user code later in stack.
so there 2 workarounds: disable just code in menu tools → options → debugging → general or remove check box user-unhandled .net framework exceptions in menu debug → exceptions dialog.
Comments
Post a Comment