In Visual Studio 2015 DebuggerStepThrough doesn

2019-06-26 04:32发布

In earlier versions of Visual Studio you could use the [DebuggerStepThrough] attribute to ignore exception in a special method which for some reason cannot be avoided (network exceptions e.g. or maybe failing parsings). (See this Thread: Don't stop debugger at THAT exception when it's thrown and caught)

Now Visual Studio shows me the exception at the calling function without the attribute even though it's already caught and processed.

Example:

    static void Main(string[] args)
    {
        ExceptionalMethod();
    }
    [DebuggerStepThrough]
    static void ExceptionalMethod()         
    {
        try
        {
            throw new Exception("BAM");
        }
        catch 
        { }
    }

This code should not stop in VS 2013 or lower. Same behaviour with DebuggerHidden.

Is there a new trick to ignore that very one exception? Without ignoring all exceptions of that type of course?

1条回答
疯言疯语
2楼-- · 2019-06-26 04:46

Microsoft deactivated the feature due to "beneficial performance improvement when debugging .NET code".

In Visual Studio 2015 Update 2 it's possible to turn the feature on/the performance improvement off by changing a registry key.

Enter this into your command line to do that:

reg add HKCU\Software\Microsoft\VisualStudio\14.0_Config\Debugger\Engine /v AlwaysEnableExceptionCallbacksOutsideMyCode /t REG_DWORD /d 1

Source: https://blogs.msdn.microsoft.com/visualstudioalm/2016/02/12/using-the-debuggernonusercode-attribute-in-visual-studio-2015/

查看更多
登录 后发表回答