c# - Visual Studio 2015 意外中断已处理的异常

标签 c# exception visual-studio-2015 exception-handling break

一张图片胜过千言万语,下面怎么可能:

Visual Studio 2015 breaking while it should not

可以看出,Visual Studio 2015(最新版本)在 Common Language Runtime Exceptions 时中断在 Exception Settings 下未选中,Enable Just My CodeTools > 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.

正如文档所说,解决方案是添加 HandleProcessCorruptedStateExceptionsAttributeStart() 方法。如果不可能(例如,这是通过库提供的),我猜您可以添加一个包装调用的方法并将属性添加到该包装方法。

关于c# - Visual Studio 2015 意外中断已处理的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39575449/

相关文章:

C# - 我应该使用什么,接口(interface)、抽象类,还是两者?

c# - 委托(delegate)的目的

c# - 在 C# 构造函数中处理损坏的输入数据的最合适方法是什么?

c# - 异常捕获最佳实践 (c#/.net)

c++ - VS2015 和 GCC 5.4.0 中的 Constexpr 阶乘编译结果

c# - 如何在特定 Controller 上实现 session 感知 WEB API?

c# - 使用 Style 将 Calendar 的宽度更改为其父 DatePicker 的宽度

c# - 如何处理通用返回 T 的异常

sql-server - Visual Studio 2015 Update 2 和 Sql Server 2016 架构比较

c# - 为什么 C# 中的计数器(使用 CRTP)不会对某些类型的对象进行倒计时?