In Java, this code throws an exception when the HTTP result is 404 range:
URL url = new URL(\"http://stackoverflow.com/asdf404notfound\"); HttpURLConnection
First check the response code and then use HttpURLConnection.getErrorStream()
HttpURLConnection.getErrorStream()