为什么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 { }
屏幕截图:
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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 .NET 4 中,默认情况下无法捕获
AccessViolationException
。请参阅 legacyCorruptedStateExceptionsPolicy 配置元素。他们这样做是因为人们在整个代码中都使用
try {} catch (Exception) {}
,并且捕获AccessViolationException
(以及其他一些异常)通常不是一个好主意并继续。此外,请参阅 http://msdn.microsoft.com/en-us/magazine/ dd419661.aspx
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 catchAccessViolationException
(along with a few others) and continue.Additionally, see http://msdn.microsoft.com/en-us/magazine/dd419661.aspx