[英]Handling AccessViolation exception in try catch c#
如何在try-catch塊中捕獲AccessViolation異常:
這是下面的代碼:
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和其他的處理損壞的狀態異常已在.NET 4被更改通常你不應該捕獲這些異常,所以運行時間已更改為反映這一點。 如果確實需要捕獲這些,則必須使用HandledProcessCorruptedStateExceptions
屬性注釋代碼。
請記住,行為是有充分理由改變的。 大多數應用程序無法以任何有意義的方式處理這些異常,因此不應該捕獲它們。
它的HandleProcessCorruptedStateExceptions不是HandleDProcessCorruptedStateExceptions
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.