1

When I do a java.net.URLConnection.connect() it gives me java.net.UnknownHostException when the server is down.

However, I've found out that if my internet connection is down, the function also throws me a java.net.UnknownHostException.

So how do I determine whether it is a problem with the server (server down) or a problem with the client (my internet connection is down) ?

Pacerier
  • 86,231
  • 106
  • 366
  • 634

1 Answers1

1

In the general case, you can't. UnknownHostException means that resolving the host-name to an IP-address failed. This could be because of a failure in the local DNS-setup, missing connection to your ISP DNS, error in /etc/hosts and probably a few other failure scenarios as well. It is easy to imagine situations where host name resolution fails but the internet connection is up, or the internet connection is down but host name resolution works.

Rolf Rander
  • 3,221
  • 20
  • 21