本文介绍了为什么 try-catch 块无法处理异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FSDKCam.GetVideoFormatList 是来自外部 .NET dll 的方法.如您所见,它在 try-catch 块中引发异常.

FSDKCam.GetVideoFormatList is a method from external .NET dll. As you see the image, it throws an exception in try-catch block.

try
{
    FSDKCam.GetVideoFormatList(ref cameraList[0], out formatList, out count);
    if (count > 0) cmbCameraList.Items.Add(cam);
}
catch { }

截图:

推荐答案

在 .NET 4 中,AccessViolationException 在默认情况下不可捕获.

In .NET 4, AccessViolationException is not catchable by default.

请参阅 legacyCorruptedStateExceptionsPolicy 配置元素.他们这样做是因为人们在整个代码中都有 try {} catch (Exception) {} 并且捕获 AccessViolationException(以及其他一些)通常不是一个好主意并继续.

See the legacyCorruptedStateExceptionsPolicy configuration element. They did this because people have try {} catch (Exception) {} throughout their code and it is usually not a good idea to catch AccessViolationException (along with a few others) and continue.

此外,请参阅 http://msdn.microsoft.com/en-us/magazine/dd419661.aspx

这篇关于为什么 try-catch 块无法处理异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 10:39