I'm writing a VB.Net app which connects to a remote server and listens for data on that port.
I've got the following function which checks that the IP/port in question is listening for connections or not. When the process on the remote port is running is works fine but when it's not running rather than the exception handler running I get an ugly dialogue box in Visual Studio rather when I run it.
Any ideas why the exception handler is not firing ?
Private Function testSelectedPort(ip As String, port As Integer) As Boolean
' Function to open a socket to the specified port to see if it is listening
' Connect to socket
Dim testSocket As New System.Net.Sockets.TcpClient()
' The socket is accepting connections
Catch ex As Exception
' The port is not accepting connections
Once the exception is thrown it should be handled by the
Catch-block. There are only a few exceptions that are generally not very easy to handle via
Try/Catch (for instance a
System.AccessViolationException), but those do not include the errors a socket might throw.
Please make sure that you haven't ticked the specific exception type to break when thrown, in the Exception Settings window