Visual Studio 2015意外地破坏处理的异常 [英] Visual Studio 2015 unexpectedly breaking on handled exceptions

查看:425
本文介绍了Visual Studio 2015意外地破坏处理的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个图像价值很多,可能如下:

An image being worth a lot of words, how is the following possible:

可以看出,Visual Studio 2015(最新版本)在通用语言运行时异常 异常设置未选中,启用我的代码工具>选项>检查调试,并且明确处理异常(在try / catch块内)。

As can be seen, Visual Studio 2015 (latest version) breaks while Common Language Runtime Exceptions under Exception Settings is unchecked, Enable Just My Code under Tools > Options > Debugging is checked, and the exception is clearly handled (within a try/catch block).

失败并导致中断的行是调用一个外部API(这是有点bug,因此try / catch块)。

The line failing and causing the break is a call to an external API (which is somewhat buggy, hence the try/catch block).

我错过了一些可以证明这个中断的理由,还是这个bug?我以为这个其他问题会提供一些洞察力它不幸没有帮助这里(异常处理,所以我们不应该启用额外的继续当用户代码未处理选项。

Am I missing something that would justify the break or is this a bug? I thought this other question would provide some insight but it unfortunately does not help here (the exception is handled so we should not need to enable the additional Continue When Unhandled in User Code option.

推荐答案

这个异常有一个特殊的例子,我猜这是在这里应用的。从 docs

There is a special case for this exception, which I am guessing applies here. From the docs:


AccessViolationException和try / catch块

从.NET Framework 4开始,公共语言运行时抛出的AccessViolationException异常不由如果异常发生在通用语言runtim保留的内存之外,则在结构化异常处理程序中的catch语句e。要处理这样的AccessViolationException异常,您应该将HandleProcessCorruptedStateExceptionsAttribute属性应用于抛出异常的方法。此更改不会影响用户代码抛出的AccessViolationException异常,这可能会继续被catch语句捕获。对于要在.NET Framework 4上重新编译并运行而不进行修改的.NET Framework以前版本的代码,可以将元素添加到应用程序的配置文件中。请注意,如果您为AppDomain.FirstChanceException或AppDomain.UnhandledException事件定义了一个处理程序,您还可以收到异常的通知。

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()方法。如果不可能(例如,这是通过库提供的),我猜你可以添加一个包装调用并将属性添加到该包装方法的方法。

As the docs say, the solution is to add the HandleProcessCorruptedStateExceptionsAttribute to the Start() method. If not possible (e.g., this is supplied via a library), I'm guessing you can add a method that wraps the call and add the attribute to that wrapping method.

这篇关于Visual Studio 2015意外地破坏处理的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆