DCSIMG
Exception by target of an invocation - Asaf Shelly

Exception by target of an invocation

Published Thursday, April 01, 2010 6:38 PM

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.

 

Comments

No Comments

Leave a Comment

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

Enter the numbers above: