任何方式在Visual Studio中不会突破特定的异常? [英] Any way in Visual Studio to not break on throwing of a specific exception?

查看:205
本文介绍了任何方式在Visual Studio中不会突破特定的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有pragma或debugger属性,即使在Debug >> Exceptions菜单下,即使在任何情况下,我已经告诉它要断开CLR异常是抛出的?



一般来说,开发中我喜欢在调试时将异常中断,以便我可以立即检查它们。有时候有一些孤立的情况,据知这个代码块偶尔会抛出异常,我已经用try-catch处理了。请参阅这个问题的答案,其中一致认为是最正确的情况。



我想要能够在方法上设置一个属性(类似于System.Diagnostics.DebuggerHiddenAttribute),它只会忽略方法中抛出的任何异常。



BTW,我目前在Visual Studio 2008中遇到这种情况,但我猜测所有版本都有一个答案,或者没有。

解决方案

可以在Debug菜单的Exceptions菜单项下找到直接的答案。这是一个解决方案/项目设置。 (工具>选项>调试是一个系统范围的设置。)请参阅帮助主题 Visual Studio Debugger,如何:在 microsoft.com/en-us/library/d14azbfh.aspxrel =noreferrer> http://msdn.microsoft.com/en-us/library/d14azbfh.aspx 的详细信息。例外对话框允许您设置抛出哪些异常或哪个异常进入调试器。



我发现从$ code> DebuggerStepThrough

一般来说,我将抛出异常给默认(Debug> Exceptions用户未处理的检查和Thrown未选中),并添加 DebuggerStepThrough 属性,对于我不感兴趣的方法,也不感兴趣在该方法中抛出的任何异常。我很少使用 DebuggerHidden ,并在库代码中更多地使用 DebuggerNonUserCode


Is there a pragma or debugger attribute which will allow the debugger to not break on the throwing of a specific exception even though under the Debug >> Exceptions menu I've told it to break when any CLR Exceptions are throw?

In general while developing I like to have it break on exceptions while debugging so that I can immediately inspect them. Sometimes there are some isolated cases where it is known that this block of code occasionally throws exceptions and I've handled it in with a try-catch. See the answer to this question where the consensus was that try-catch is the most correct situation.

I'd like to be able to set an attribute on the method (something analogous to System.Diagnostics.DebuggerHiddenAttribute) which just ignores any exceptions thrown in the method.

BTW, I'm currently experiencing this in Visual Studio 2008, but I'm guessing there is either an answer for all versions or none.

解决方案

The direct answer can be found under Exceptions menu item of the Debug menu. This is a per solution/project setting. (Tools > Option > Debugging is a system-wide setting.) See the help topic Visual Studio Debugger, How to: Break When an Exception is Thrown at http://msdn.microsoft.com/en-us/library/d14azbfh.aspx for details. The Exceptions dialog allows you to set which exceptions are thrown or which exceptions break into the debugger.

I find I get more use out of the DebuggerStepThrough attribute.

In general, I leave throwing exceptions to the default (Debug > Exceptions user-unhandled checked and Thrown unchecked) and add the DebuggerStepThrough attribute for methods where I am not interested in stepping through nor am I interested in any exceptions being thrown within that method. I rarely use DebuggerHidden, and get more use with DebuggerNonUserCode in library code.

这篇关于任何方式在Visual Studio中不会突破特定的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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