ATTENTION: this may depend on the JVM version you are running!!! as tests of @SotiriosDelimanolis gave different results
The answer is in the source code of the HttpURLConnection and is related to all the errors that have error code > 400
If error code is equal 404 or 410 a FileNotFoundException is thrown else an IOException as
if (respCode >= 400) {
if (respCode == 404 || respCode == 410) {
throw new FileNotFoundException(url.toString());
} else {
throw new java.io.IOException("Server returned HTTP" +
" response code: " + respCode + " for URL: " +
url.toString());
}
}
sun.net.www.protocol.http.HttpURLConnection Source code at line 1625:
My test on http://media.jarnbjo.de/412.php using :
Java(TM) SE Runtime Environment (build 1.7.0_21-b11) Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)
on Windows 64 bit