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

前端之家收集整理的这篇文章主要介绍了c# – 调试时是否可以完全忽略catch块?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在WinForms(.net 3.5)中工作,并具有以下代码行:
  1. HitTestResult result;
  2. try
  3. {
  4. result = this.HitTest( e.X,e.Y,ChartElementType.DataPoint);
  5. }
  6. catch(Exception e)
  7. {
  8. //This happens,we don't care!
  9. }

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

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

谢谢!

解决方法

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

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

例如:

  1. [DebuggerStepThrough]
  2. public void MyMethod()
  3. {
  4. HitTestResult result;
  5. try
  6. {
  7. result = this.HitTest(e.X,ChartElementType.DataPoint);
  8. }
  9. catch (Exception e)
  10. {
  11. //This happens,we don't care!
  12. }
  13. }

猜你在找的C#相关文章