我可以让 Visual Studio 忽略异常的特定*实例*吗? [英] Can I get Visual Studio to ignore a specific *instance* of an exception?

查看:25
本文介绍了我可以让 Visual Studio 忽略异常的特定*实例*吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用第 3 方代码,该代码抛出并捕获 NullReferenceException 作为其正常、正确操作的一部分.我希望能够告诉 Visual Studio 忽略这个实例(即,忽略从这个 .cs 文件 + 行号抛出的 NullReferenceExceptions),但继续打破其他抛出 NullReferenceException s.

这可能吗?

第三方代码我的意思是作为项目一部分的源代码,但我不拥有并且不会修改.例如,我不能使用依赖于 VS 定义的用户代码的任何内容,因为这也算作用户代码.项目的规模意味着这个细节是我无法控制的.出于类似的原因,我不想添加 [DebuggerHidden].

解决方案

正如其他人所提到的,如果在 3rd 方代码(调试器对3rd 方代码"是未优化的程序集中的代码并且我们没有 .pdbs 用于),然后为了避免调试器停止它,您只需转到工具->选项->调试->常规并启用仅我的代码".

如果有问题的代码不是 3rd 方代码,您可以向其添加 DebuggerNonUserCode 属性,以控制调试器是否会在装饰方法中因异常而中断(同样,假设只是我的代码"已启用).

在 VS "15" Preview 5 中,您实际上可以

免责声明:我是我刚刚提到的工具的共同创建者.

I am working with 3rd-party code that throws and catches a NullReferenceException as part of its ordinary, correct operation. I would like to be able to tell Visual Studio to ignore this instance (ie, ignore NullReferenceExceptions thrown from this .cs file + line number) but continue to break on other thrown NullReferenceExceptions.

Is this possible?

edit: By 3rd party code I mean source code that is part of the project, but that I don't own and won't be modifying. I can't use anything that relies on VS's definition of user code, for example, because this also counts as user code. The size of the project means that this detail is out of my control. For similar reasons I don't want to add [DebuggerHidden].

解决方案

As others have mentioned, if an exception is truly caught and handled inside 3rd party code (where the debugger's definition of "3rd party code" is code that is in an assembly which is non-optimized AND we don't have .pdbs for), then to avoid the debugger from stopping on it, you simply need to go to Tools->Options->Debugging->General and enable "Just My Code".

If the code in question is not 3rd party code, you can add a DebuggerNonUserCode attribute to it, to control whether the debugger will break on an exception in the decorated method (again, assuming "Just My Code" is enabled).

In VS "15" Preview 5, you can actually disable breaking on an exception when it's thrown inside a specific module, but that's not available in VS2015.

Another option to workaround this quickly, is to use OzCode which has a ToolBar button for toggling "Break on All CLR Exceptions". This is a really quick way of enabling/disabling all exceptions, which you can toggle before you know the annoying NullReferenceException is about to occur.

Disclaimer: I'm co-creator of the tool I just mentioned.

这篇关于我可以让 Visual Studio 忽略异常的特定*实例*吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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