如何捕捉在try-catch块的AccessViolation例外:处理AccessViolation异常C#
这里是下面的代码:
public static BP GetBloodPressure(string vendorid, string productid)
{
BP Result = new BP();
try
{
GETBPData BPreadings = new GETBPData();
UInt16 VendorId = Convert.ToUInt16(vendorid, 16);
UInt16 ProductId = Convert.ToUInt16(productid, 16);
if (HealthMonitorData.HidDataTap_GetBloodPressure(VendorId, ProductId, ref BPreadings)) // error here
{
if (BPreadings.ucSystolic == 0 && BPreadings.ucDiastolic == 0 && BPreadings.DeviceId1 == 0 && BPreadings.DeviceId2 == 0 && BPreadings.ucPulse == 0)
{
Result = null;
}
else
{
Result.UcSystolic = BPreadings.ucSystolic;
Result.UcDiastolic = BPreadings.ucDiastolic;
Result.UcPulse = BPreadings.ucPulse;
Result.DeviceId1 = BPreadings.DeviceId1;
Result.DeviceId2 = BPreadings.DeviceId2;
}
}
}
catch (Exception ex)
{
}
return Result;
}
我导入一个DLL来读取血压值从设备。我试图捕获异常,但控制不会超出访问冲突异常即将发生时的“if”语句。
请建议?
感谢AccessViolationExceptions的
修复你的代码,不追赶这些例外。 – leppie 2010-12-03 05:50:23
也,如何解决我的代码使用外部的DLL。 – Tarun 2010-12-03 06:29:04