Visual Studio: edit-and-continue on handled exceptions?

Viewed 739

Here's a code reproducing the behavior I'm expecting to get:

    static void Main(string[] args)
    {
        // try // #2
        {
            string x = null; // #1
            AssertNotNull(x, nameof(x));
        }
        // catch (ArgumentNullException) { } // #2
        Console.WriteLine("Passed.");
        Console.ReadKey();
    }

    [DebuggerHidden]
    public static void AssertNotNull<T>(T arg, string argName) where T : class
    {
        if (arg == null)
            throw new ArgumentNullException(argName);
    }

The behavior is the same for any VS starting from VS2008 (did not check on earlier versions).

If you run it under debug (using a standard debugging settings) you're not allowed to continue until you fix the code (using the EnC). Hitting F5 will just rerun assertion due to [DebuggerHidden] and "Unwind stack on unhandled exception" setting combo (setting is enabled by default).

To fix the code, just replace the #1 line with object x = "", set the next statement to it and hit F5 again.

Now, enable "break when thrown" for the ArgumentNullException and uncomment the lines marked with #2. The behavior changes: you're stopped on assertion again, but the stack does not unwind (easy to check with CallStack window). F5 will continue from the place the exception was thrown.

Ok, so... now the question is: Is there any way to enable auto stack unwinding when breaking on handled exceptions?

Hidden VS option, existing extension or (maybe) API that can be used from my own extension?

UPD: To clarify the question: I want to break at the line with failed assertion, edit the code with edit and continue, set next statement to the fixed code and continue the execution.

As it works if the exception is not caught down the stack.

UPD2 As proposed by Hans Passant: Posted an suggestion on UserVoice. Feel free to vote:)

2 Answers
Related