When you do an HTTP request to a webserver, it sends back (as part of the response headers) a status code.
This status code is normally 200.
You're probably familiar with 404 (file not found), 403 (not allowed), and 500 (internal server error).
All those are errors you can trap.
Likewise,
you should be able to define some means to determine that a server is not responding at all (possibly a timeout trying to talk to it could be used for that).
Look into HttpURLConnection