prevent调试器的第三方库的所有例外打破 [英] Prevent debugger to break on all Exceptions in a 3rd party library

查看:160
本文介绍了prevent调试器的第三方库的所有例外打破的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为,内部使用异常的递归方法调用过程中的开源库。异常被收回在调用堆栈和在某些情况下处理的,而在其他情况将被返回给调用者。

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 in others it will be returned to the caller.

我们有现在的问题是,有些用户正在运行的Visual Studio调试器与选项中的对所有异常暂停,所以他们的调试器将在我们的code暂停,而其工作正常。

The problem we are having right now is that some users are running Visual Studio Debugger with the "Halt on ALL exceptions" option, so their debugger will halt in our code while it is functioning normally.

有没有什么办法prevent这种情况的发生不是告诉用户禁用该设置其他?像,应用一些属性到code可能?

Is there any way to prevent that from happening other than telling users to disable that setting? Like, applying some attribute to the code maybe?

推荐答案

这是非常可能的。所有你需要做的是让Visual Studio中看到相关的code为非用户code 的,然后启用只是我的code在调试器设置选项:

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:

说服力的Visual Studio,你的图书馆是几种方法没有用户code 。一种是简单地编译一个发布版本没有PDB文件。另一种是 DebuggerNonUser $ c标记的code $ cAttribute

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.

有一个示范项目显示在操作这个东西: https://bitbucket.org/rstarkov/demononuser$c$c/src - 注意:在MyLibrary的方法怎么样都标有非用户自code属性。即使你告诉Visual Studio来停止抛出对所有的异常,它仍然会跳过异常MyLibrary的。

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.

这篇关于prevent调试器的第三方库的所有例外打破的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆