【问题标题】:Prevent Breaking On Handled Exceptions防止中断处理的异常
【发布时间】:2019-07-04 05:52:19
【问题描述】:

我在“ExceptionSettings”窗口中检查了“Common Language Runtime Exceptions”的所有异常,但是这一次,Visual Studio 会中断执行,即使是 try-catch 块内的异常也是如此。当遇到任何类型的异常但只有在 try-catch 内没有处理时,如何让它中断执行?

【问题讨论】:

    标签: c# .net visual-studio


    【解决方案1】:

    只需转到 Debug -> Windows -> Exceptions 并确保未检查任何异常。

    那么 VS 不应该因任何异常而中断。

    请参阅this

    对于未处理的异常,VS 默认会中断,只需在异常设置中尝试使用选中的这个简单代码,然后取消选中 InvalidCastException

    private void TestMethod()
    {
      try
      {
        var i = 0;
        throw new InvalidCastException();
      }
      catch(InvalidCastException ex)
      {
        var j = 0;
      }
      throw new InvalidCastException();
    }
    

    【讨论】:

    • 感谢您的回答,但不幸的是它不能解决我的要求。我想中断所有类型的异常,但如果异常是由我在 try-catch 中处理的,我不想中断。
    • @hakanviv 如果它没有处理,那么 VS 无论如何都会中断它:)
    猜你喜欢
    • 2013-11-12
    • 1970-01-01
    • 1970-01-01
    • 2011-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-01
    相关资源
    最近更新 更多