我把try/catch塊放在偶爾會引發預期異常的代碼中,而不是捕獲它並顯示消息框,它會停止調試器並警告我該異常未處理。爲什麼try/catch沒有捕獲訪問衝突?
如何處理此異常,以便在發生異常時不會停止代碼?
Friend myDevInfo As New devInfo
''' <summary>
''' Closes the device handle obtained with CreateFile and frees resources.
''' </summary>
'''
Friend Sub CloseDeviceHandle()
Try
WinUsb_Free(myDevInfo.winUsbHandle)
If Not (myDevInfo.deviceHandle Is Nothing) Then
If Not (myDevInfo.deviceHandle.IsInvalid) Then
myDevInfo.deviceHandle.Close()
End If
End If
Catch ex As System.AccessViolationException
MsgBox("System.AccessViolationException")
Catch ex As Exception
Throw
End Try
End Sub
你已經調試 - >例外配置爲停止對異常? – 2012-04-25 08:52:44
我相信默認設置是打破'AccessViolationException' – Xharze 2012-04-25 08:54:07
你不應該試圖捕捉'AccessViolationException'。你應該修復造成它的錯誤。這個例外不應該被期望。 – CodesInChaos 2012-04-25 08:58:58