title: C# - Avoid getting a SocketException
body: <p>I was wondering if there's a way to <strong>avoid</strong> getting a SocketException whenever I cannot connect rather than catching the SocketException using try/catch.</p>
  
  <p>I have this code which checks if a server is available of not:</p>
  
  <pre><code>public bool CheckServerStatus(string IP, int Port)
      {
          try
          {
              IPAddress[] IPs = Dns.GetHostAddresses(IP);
  
              using (Socket s = new Socket(AddressFamily.InterNetwork,
                  SocketType.Stream,
                  ProtocolType.Tcp))
              s.Connect(IPs[0], Port);
  
              return true;
          }
          catch (SocketException)
          {
              return false;
          }
      }
  </code></pre>
  
  <p>Thanks in advance.</p>