Please consider this short console app code.
static void Main(string[] args)
{
try
{
Action a = () =>
{
throw new ApplicationException("Oops");
};
var ar = a.BeginInvoke(null, null);
ar.AsyncWaitHandle.WaitOne();
try
{
a.EndInvoke(ar);
Console.WriteLine("No message");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
finally
{
Console.ReadKey();
}
}
When run Visual Studio will break on the throw
complaining that its unhandled. When executed outside of the debugger the code does what I expect (displays "Oops").
How do I convince Visual Studio to allow the code to execute as it would do in the real world?
To turn off stop on exceptions press " Ctrl + Alt + E ". This will open the Exceptions window . Untick "Common Language Runtime Exceptions - Thrown". That would prevent it from pausing from within the delegate, but not when it's rethrown on Wait .
To change this setting for a particular exception, select the exception, right-click to show the shortcut menu, and select Continue When Unhandled in User Code. You may also change the setting for an entire category of exceptions, such as the entire Common Language Runtime exceptions).
Remove breakpoints For non-exception breakpoints: click the breakpoint in the gutter. For all breakpoints: from the main menu, select Run | View Breakpoints Ctrl+Shift+F8 , select the breakpoint, and click Remove Delete .
Go to the Debug menu, Exceptions. Now run your code under the debugger and vs will break whenever an exception is thrown. Now open the call stack (Debug > Window > Call Stack) to see what functions are causing the problem.
You can apply the DebuggerNonUserCode attribute to a method to hide it from the debugger.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With