为什么try-catch块不能处理异常? [英] Why try-catch block cannot handle the exception?

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

问题描述

FSDKCam.GetVideoFormatList 是外部.NET DLL的一种方法。当你看到图像时,它会在try-catch块中抛出异常。

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

截图:





请参阅 legacyCorruptedStateExceptionsPolicy 配置元素。他们这样做是因为人们在他们的代码中有 try {} catch(Exception){} ,通常不是一个好主意来捕捉 AccessViolationException (以及其他几个)并继续。



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


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 { }

Screenshot:

解决方案

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

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.

Additionally, see http://msdn.microsoft.com/en-us/magazine/dd419661.aspx

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

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