Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Visual Studio debugging breaking on an apparent "unhandled exception"

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?

like image 344
AnthonyWJones Avatar asked Oct 07 '11 09:10

AnthonyWJones


People also ask

How do I stop Visual Studio from breaking on exception?

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 .

How do I fix unhandled exception in Visual Studio?

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).

How do I stop exception breakpoint?

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 .

Where is the unhandled exception in Visual Studio?

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.


1 Answers

You can apply the DebuggerNonUserCode attribute to a method to hide it from the debugger.

like image 162
dtb Avatar answered Oct 28 '22 13:10

dtb