gpt4 book ai didi

.net - 为什么 try/catch 没有捕获访问冲突?

转载 作者:行者123 更新时间:2023-12-01 01:19:07 25 4
gpt4 key购买 nike

我在一些偶尔抛出预期异常的代码周围放置了一个 try/catch 块,但它没有捕获它并显示消息框,而是停止调试器并提醒我异常未处理。

如何处理此异常,以便我的代码在异常发生时不会停止?

enter image description here

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 -> Exceptions 下定义调试器中断的异常,我相信默认值是中断 AccessViolationException .

关于.net - 为什么 try/catch 没有捕获访问冲突?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10312296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com