Exception by target of an invocation

April 1, 2010

Parallel Programming means that we use invocations more often than we did before. Visual Studio 2008 debugger will bring you to the correct line if you get an exception, but if you invoke a method within your own code the debugger will show you the location in your own thread, which means the line that invoked the code that eventually threw an exception. The exception would say “Exception has been thrown by the target of an invocation.“.

To solve this and really find the location of your exception you can drill down into the inner-exception member of the exception or use the following coding style:

void MyInvokedFunction( ){   try   {      … some code …   }   catch (Exception exp)   {      if (Debugger.IsAttached) Debugger.Break();      else throw;   }


This will cause the debugger to stop at the source of the exception even if it was thrown by another thread.


Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>