4

I'm currently using a library that throws (and handles) about 5 exceptions when a request to get something fails. Normally this isn't a problem since it's expected this might happen, but the problem is that Visual Studio will log these exceptions anyway.

Is there a way to disable Visual Studio from outputting caught exceptions to the debug console? I still want all other exceptions that would cause a break to be logged.

trigger_segfault
  • 554
  • 1
  • 6
  • 23

1 Answers1

5

You can ask Visual Studio to care about the exceptions in your code only, using the Just My Code option.

Go to the "Debug" menu and click on "Options and Settings", and then Enable Just My Code:

Just My Code

This has been discussed on StackOverflow too.

Then, if the methods that are throwing the exception belong to a project that is... your code, you can decorate them with the DebuggerNonUserCode attribute:

DebuggerNonUserCode

which combined with the "Just My Code" option will produce the desired behaviour. More on the topic here.

Francesco B.
  • 2,729
  • 4
  • 25
  • 37
  • 2
    Currently the library throwing the error is compiled by me due to the NuGet version lacking the latest fixes. Is there a way to disable them for specific projects? EDIT: Looks like just putting them in Release mode solves that problem. Just My Code was already enabled. Thanks! – trigger_segfault Apr 22 '18 at 19:58
  • 1
    I added a possible solution to my answer, to take that into account. – Francesco B. Apr 22 '18 at 20:05
  • 1
    I read that `DebuggerNonUserCode` works only after executing the following command: `reg add HKCUSoftwareMicrosoftVisualStudio14.0_ConfigDebuggerEngine /v AlwaysEnableExceptionCallbacksOutsideMyCode /t REG_DWORD /d 1` This registry key will only work in Visual Studio 2015 Update 2 and beyond. Source: https://devblogs.microsoft.com/devops/using-the-debuggernonusercode-attribute-in-visual-studio-2015/ – Roland Pihlakas Aug 14 '23 at 15:02