【发布时间】:2012-10-04 16:03:20
【问题描述】:
我正在使用一些外部代码,当使用某些参数调用这些代码时会引发可以忽略的异常。不幸的是,由于各种原因,我无法更改此外部代码。
我创建了一个看起来像这样的包装方法:
[DebuggerStepThrough]
public static bool TryGetXXX(string input, out string output)
{
try
{
output = MethodThatSometimesFails(input);
return true;
}
catch
{
output = null;
return false;
}
}
private static string MethodThatSometimesFails(string input)
{
// Don't want this to cause a break
// but can not put the attribute on this method
throw new Exception("couldnt deal with your request");
}
不幸的是,外部代码仍然会在MethodThatSometimesFails 内的异常处中断。 [DebuggerStepThrough] 只会避免调试上面的代码,但是被调用的代码还是会抛出。
我想要的是,即使选中“异常...”窗口上的所有复选框,代码也能运行。有没有可以做到这一点的属性?
如果没有属性,我可以创建一个包含这些类/方法的项目并排除整个项目。有没有办法做到这一点?
【问题讨论】:
-
工具->Optoins->调试->当异常跨 AppDomain 设置时中断? social.msdn.microsoft.com/Forums/en-US/csharpide/thread/…
-
你得到这个是因为调试器配置设置:调试+异常,抛出复选框。除了取消选中该复选框之外,您无能为力。
-
我希望抛出此方法之外的其他异常并让我看到它们,所以我想不取消选中抛出的复选框是这个问题的目的。作为一名开发人员,我总是想知道我的部分代码中的异常是否在开发阶段被抛出。错误的类型是 ApplicationException,所以我必须通过取消选中它来限制它。
标签: c# .net attributes visual-studio-debugging