Why isn't the try/catch catching the access violation?
.net, exception, vb.net
Solution
The `try...catch` block should work as expected, when no debugger is attached. You can define what exceptions the debugger breaks on under Debug -> Exceptions, I believe the default is to break on `AccessViolationException`.
Problem
I put a try/catch block around a bit of code that occasionaly throws an expected exception, but rather than catching it and displaying the message box, it stops the debugger and alerts me that the exception is unhandled. How do I handle this exception so my code doesn't stop when the exception occurs? ``` 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 ```