问题
So I have this chunk of code, and when debugging in Visual Studio, it's breaking even though the exception is handled in my code. I only want it to break when this exception is unhandled by my code. The Exceptions Settings box only has an option to continue on unhandled exceptions in user code, but that's not acceptable because I still need it to break if it's unhandled. I've seen screenshots of previous versions of VS that had an option for this. Is this a VS 2015 bug or did microsoft remove the functionality, or am I just missing something here?
回答1:
In the Exception Settings window, when they are checked like they are in your picture it will always break, even if handled (notice the window says Break When Thrown
).
You can right-click on the Common Language Runtime Exceptions
and select Restore Defaults
in the context menu, which will change it back to only break when unhandled.
回答2:
The VS2015 really changed certain settings, but you could use "Continue when unhandled in user code" after you enable the Just My Code under TOOLS->Options->Debugging->General, it has the same feature as the old VS version with the second column in the Exception window.
More detailed information, please refer to the following blogs:
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
回答3:
It has happened to me before, what I did:
- I stopped debugging, and
- Clean up the solution OR Restart your Visual Studio.
I hope it works for you as well.
回答4:
So it turns out this is a known issue when using NUnit testing. NUnit essentially has a giant try/catch around your code, so VS thinks it's handled.
See this question: Why doesn't Visual Studio break on exceptions when debugging unit tests?
来源:https://stackoverflow.com/questions/43329155/how-do-i-make-visual-studio-2015-ignore-handled-exceptions