cをトライキャッチでAccessViolation例外の取り扱い:は、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;
}
私は血圧値を読み取るために1つのDLLをインポートしています:ここ
は、以下のコードでありますデバイスから。私は例外をキャッチしようとしているが、コントロールはアクセス違反の例外が来ている "if"ステートメントを超えていません。
お勧めですか?
おかげAccessViolationExceptionsの
はあなたのコードを修正し、これらの例外をキャッチいけません。 – leppie
また、外部DLLを使用していると私のコードを修正する方法? – Tarun