如何让 Visual Studio 2015 忽略已处理的异常?

How do I make Visual Studio 2015 ignore handled exceptions?

所以我有这段代码,当在 Visual Studio 中调试时,即使在我的代码中处理了异常,它也会中断。我只希望它在我的代码未处理此异常时中断。 Exceptions Settings 框只有一个选项可以继续处理用户代码中未处理的异常,但这是不可接受的,因为如果未处理,我仍然需要它中断。我看过以前版本的 VS 的屏幕截图,其中有一个选项。这是 VS 2015 错误还是微软删除了该功能,或者我只是在这里遗漏了什么?

在异常设置 window 中,当它们像在您的图片中一样被检查时,它总是会中断,即使被处理(注意 window 说 Break When Thrown)。

您可以在上下文菜单中右键单击 Common Language Runtime Exceptions 和 select Restore Defaults,这会将其更改回仅在未处理时中断。

我以前也遇到过,我是怎么做的:

  1. 我停止了调试,并且
  2. 清理解决方案 要么 重启你的 Visual Studio.

我希望它也对你有用。

VS2015确实改变了一些设置,但是你可以在TOOLS->Options->Debugging->General下启用Just My Code后使用"Continue when unhandled in user code",它与旧版VS具有相同的功能异常 window.

中的第二列

更详细的信息,请参考以下博客:

https://blogs.msdn.microsoft.com/visualstudioalm/2015/02/23/the-new-exception-settings-window-in-visual-studio-2015/

https://blogs.msdn.microsoft.com/visualstudioalm/2015/01/07/understanding-exceptions-while-debugging-with-visual-studio/#user-unhandled

事实证明这是使用 NUnit 测试时的一个已知问题。 NUnit 本质上在您的代码周围有一个巨大的 try/catch,因此 VS 认为它已被处理。

看到这个问题:Why doesn't Visual Studio break on exceptions when debugging unit tests?