一张图片胜过千言万语,下面怎么可能:
可以看出,Visual Studio 2015(最新版本)在 Common Language Runtime Exceptions
时中断在 Exception Settings
下未选中,Enable Just My Code
在 Tools > Options > Debugging
下已检查,异常已明确处理(在 try/catch block 内)。
失败并导致中断的行是对外部 API 的调用(这有点错误,因此是 try/catch block )。
我是否遗漏了一些可以证明中断的东西,或者这是一个错误?我以为this other question会提供一些见解,但不幸的是,它在这里没有帮助(异常已处理,因此我们不需要启用额外的 Continue When Unhandled in User Code
选项。
最佳答案
这个异常(exception)有一个特例,我猜这里也适用。来自docs :
AccessViolationException and try/catch blocks
Starting with the .NET Framework 4, AccessViolationException exceptions thrown by the common language runtime are not handled by the catch statement in a structured exception handler if the exception occurs outside of the memory reserved by the common language runtime. To handle such an AccessViolationException exception, you should apply the HandleProcessCorruptedStateExceptionsAttribute attribute to the method in which the exception is thrown. This change does not affect AccessViolationException exceptions thrown by user code, which can continue to be caught by a catch statement. For code written for previous versions of the .NET Framework that you want to recompile and run without modification on the .NET Framework 4, you can add the element to your app's configuration file. Note that you can also receive notification of the exceptions if you have defined a handler for the AppDomain.FirstChanceException or AppDomain.UnhandledException event.
正如文档所说,解决方案是添加 HandleProcessCorruptedStateExceptionsAttribute到 Start()
方法。如果不可能(例如,这是通过库提供的),我猜您可以添加一个包装调用的方法并将属性添加到该包装方法。
关于c# - Visual Studio 2015 意外中断已处理的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39575449/