为什么try-catch块不能处理异常? [英] Why try-catch block cannot handle the exception?
问题描述
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屋!