我在一些代码中放置了一个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当没有附加调试器时,try … catch块应该按预期工作. 您可以在Debug – >下定义调试器中断的异常.例外,我认为默认是在AccessViolationException上中断.