4

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?

Community
  • 1
  • 1
  • Please explain what you mean here. If I enable "stop on all thrown exceptions" on "Common language runtime exceptions", both Visual Studio 2012 and 2015 stops, though they stop in different locations. 2012 stops on the throw-statement but 2015 stops on the outer method call. If I disable the same setting, neither version stops. Please clarify. – Lasse V. Karlsen Jul 31 '15 at 08:23
  • 2
    Visual Studio 2013 doesn't stop at all for me with the attribute set. –  Jul 31 '15 at 08:37
  • 3
    This was also the way VS2013 RTM behaved, the Connect feedback report [is here](https://connect.microsoft.com/VisualStudio/feedback/details/800415/regression-debugger-incorrectly-breaks-on-exceptions-caught-in-debuggerstepthrough-code). Fixed in Update 2. The debugger team has a pretty unhealthy track-record of incorporating post-release bug fixes back into their main branch. Nothing we can do about it, I recommend you file a feedback report. – Hans Passant Jul 31 '15 at 12:09

1 Answers1

4

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/