我把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