locked
Cannot Set Next Statement using Visual Studio 2015 debugger RRS feed

  • Question

  • I have a breakpoint set at the "throw" statement. When the breakpoint is hit, I want to set the next statement to the end of the function so as not to trigger the exception. But the debugger thinks I want to set the next statement to a different function instead.

            private void MoveRowIndex()
            {
                throw new NotImplementedException();
            }

    This is just an example. The same issue exists in javascript as well. Basically you cannot skip the statement if it's the last statement in a function. What gives?

    Thursday, August 4, 2016 4:43 AM

Answers

  • Looks like optimization for me. Compiler generates no instructions for code, which it decides to be unreachable.
    Possibly for debugging purpose something like this may work (debug configuration c#):
    #if DEBUG
                int x = 0;
                if (x != 1)
    #endif
                    throw new NotImplementedException();


    With kind regards
    Friday, August 5, 2016 8:06 AM

All replies

  • You already looked up in Disassembly-Window, if compiler did some optimizations? E. g. omitting function epilog.

    With kind regards

    Thursday, August 4, 2016 8:06 AM
  • I don't see a "ret" in the disassembly shown below:

    I decided to comment out the throw statement and put a return statement instead. Now I can move past the return statement. So perhaps the fact that it was a throw statement that prevented me from setting the next statement?

    Friday, August 5, 2016 3:43 AM
  • Could you put a ; above the throw and put the bp on it. Once it breaks on ; then skip the throw call? Not sure if that helps, I can't tell what the use case would be with the code example.
    Friday, August 5, 2016 4:13 AM
  • Hi Joe_Z,

    I tried your approach but it still didn't work. I was having this type of issue with javascript originally but once I saw the same issue in C#, I decided to post to this forum. Let me revise my example as follows:

    I have a breakpoint set in my javascript as shown below. I want to skip the statement $("#rightCommand").toggleClass("hidden"). Being that it's the last statement in this function, it simply won't let me skip it. I suppose it's just an obscure bug in VS 2015.

    Friday, August 5, 2016 6:37 AM
  • Looks like optimization for me. Compiler generates no instructions for code, which it decides to be unreachable.
    Possibly for debugging purpose something like this may work (debug configuration c#):
    #if DEBUG
                int x = 0;
                if (x != 1)
    #endif
                    throw new NotImplementedException();


    With kind regards
    Friday, August 5, 2016 8:06 AM