如何捕捉在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