【发布时间】:2013-03-27 20:14:08
【问题描述】:
我有这样的东西:
try
{
instance.SometimesThrowAnUnavoidableException(); // Visual Studio pauses the execution here due to the CustomException and I want to prevent that.
}
catch (CustomException exc)
{
// Handle an exception and go on.
}
anotherObject.AlsoThrowsCustomException(); // Here I want VS to catch the CustomException.
在代码的另一部分中,我遇到了多次引发 CustomException 的情况。我想强制 Visual Studio 停止在 instance.SometimesThrowAnUnavoidableException() 行上中断,因为它掩盖了我有兴趣在 CustomException 上中断的其他地方的视图。
我尝试了 DebuggerNonUserCode,但目的不同。
如何禁止 Visual Studio 仅在特定方法中捕获特定异常?
【问题讨论】:
-
什么版本的 Visual Studio?在 2012 年,您只需取消勾选“中断此类异常”
-
AFAIK 这是不可能的 - 您可以为特定的异常类型打开和关闭中断,但不能为特定的代码部分。
-
不要使用异常来控制流,当你必须调试它们时你会后悔。以 DateTime.TryParse() 方法为例,该方法旨在避免在可能发生异常的地方出现异常。
-
我会在另一个类中验证它。
-
我会和那个班的程序员谈谈。而不是互联网上的一些随机的人。
标签: c# visual-studio exception exception-handling