In Java, this code throws an exception when the HTTP result is 404 range:
URL url = new URL(\"http://stackoverflow.com/asdf404notfound\"); HttpURLConnection
InputStream is = null; if (httpConn.getResponseCode() !=200) { is = httpConn.getErrorStream(); } else { /* error from server */ is = httpConn.getInputStream(); }