微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 调试时是否可以完全忽略catch块?

我在WinForms(.net 3.5)中工作,并具有以下代码行:
HitTestResult result;
     try
     {
        result = this.HitTest( e.X,e.Y,ChartElementType.DataPoint);
     }
     catch(Exception e)
     {
        //This happens,we don't care!
     }

我无法控制HitTest是否抛出异常,但如果是这样,我绝对不在乎.

是否可以禁用我的IDE停止在这个SPECIFIC catch块?我明白我可以禁用它可能抛出的System.FormatException(从Debug->例外菜单,但这是一种过度的杀戮.

谢谢!

解决方法

您可以使用 DebbugerStepThrough属性跳过该行.从MSDN:

Instructs the debugger to step through the code instead of stepping
into the code.

例如:

[DebuggerStepThrough]
public void MyMethod()
{
    HitTestResult result;
    try
    {
        result = this.HitTest(e.X,ChartElementType.DataPoint);
    }
    catch (Exception e)
    {
        //This happens,we don't care!
    }
}

原文地址:https://www.jb51.cc/csharp/94896.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐