Visual Studio behaves strangely when debugging with breakpoint conditions

The method I work with is called tens of thousands of times, which have started throwing exceptions lately. In most debugging cases, I set a breakpoint at the top of this method and would skip until I get to the call that interests me, with a parameter that throws an exception. In this case, this would be impractical, so I tried to set a breakpoint with a condition that would only break when this parameter value appears. I created a breakpoint at the position below and gave it a condition str == "OffendingValue".

class Foo
{
    // Bar() is called many, many times
    void Bar(string str)
    {
        try
        {
            // Breakpoint inserted here
            ...
        }
        catch (Exception ex)
        {
            ...
        }
    }
}

, , Visual Studio . , . Visual Studio - , , 15 , . , . , . - Break All, , , , , , , .

- Visual Studio? Hit Count .

+3
3

, Visual Studio, . , . if . , , .

class Foo
{
    // Bar() is called many, many times
    void Bar(string str)
    {
        try
        {

            if(str == "condition")
            {
                int i = 0;   // Breakpoint inserted here
            }
            ...
        }
        catch (Exception ex)
        {
                ...
        }
    }
}
+7

, , unit test ?

, , , . Debug | .

+2

I wonder if you get a stack overflow. Does VS control all the values ​​for str, or something in common with each state of the bar? If so, thousands of copies can be added.

I wonder if the problem of controlling the value can be fixed instead of a global variable instead.

0
source

Source: https://habr.com/ru/post/1699538/


All Articles