Prevent debugger to break on all Exceptions in a 3rd party library

前端 未结 4 1932
無奈伤痛
無奈伤痛 2021-01-22 05:44

I maintain an open source library that internally uses exceptions during a recursive method call. The exception is taken back on the call stack and in some cases handled, while

4条回答
  •  走了就别回头了
    2021-01-22 06:03

    This is very much possible. All you need to do is to get Visual Studio seeing the relevant code as non-user code, and then enable the "Just my code" option in the debugger settings:

    enter image description here

    There are several ways of convincing Visual Studio that your library is not user code. One is to simply compile a release build without PDB files. Another is to mark your code with DebuggerNonUserCodeAttribute.

    There’s a demo project showing this stuff in action: https://bitbucket.org/rstarkov/demononusercode/src – note how the methods in MyLibrary are marked with the non-user-code attribute. Even if you tell Visual Studio to stop on "Thrown" for all exceptions, it will still skip the exception in MyLibrary.

    For what it’s worth, I do not consider what you’re doing to be wrong. It’s a question of configuring the debugger properly. Not using any exceptions just because someone has set their debugger to stop on everything does not exactly sound right.

提交回复
热议问题