Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27469

VS 2008 How to catch exception in this code?

$
0
0
What is the best way to catch the exception from this code? I have put the Try Catch in there but it is still crashing after a few attempts. It works fine on an asp.net website for the first few times and then the application pool is disabled because of the crashes which I assume are the exceptions. So how can I change this so it does not throw exceptions? Not sure why it does since it works fine for 5 - 7 times and then doesn't after that.

Thanks

Code:

  Private Function CheckOnline(ByVal IP2 As String, ByVal Port2 As String) As Boolean
        Try
            Dim Port3 As Integer = 0
            If IsNumeric(Port2) = True Then
                Port3 = Val(Port2)
            Else
                Return False
            End If
            Dim s As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
            Try
                Dim success
                Dim result
                s.Connect(IP2, Port2)
                'result = s.Connect(IP2, Port3, New AsyncCallback(AddressOf s.EndConnect), s)
                'success = result.AsyncWaitHandle.WaitOne(1000, True)
                s.Disconnect(False)
                Return success
            Catch ex As Exception
                Response.Write("EE1: " & ex.Message)
                Return False
            Finally
                s = Nothing
            End Try

        Catch ex As Exception
            Response.Write("EE2: " & ex.Message)
            Return False
        End Try       
    End Function


Viewing all articles
Browse latest Browse all 27469

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>