static InputStream urlConnection_getInputStream(URLConnection con) throws IOException { UnknownHostException lastException = null; repeat 2 { try { if (con cast HttpURLConnection) if (con.getResponseCode() == 500) throw new IOException(joinNemptiesWithColonSpace("Server code 500", tryToReadErrorStreamFromURLConnection(con))); ret con.getInputStream(); } catch (UnknownHostException e) { lastException = e; print("Retrying because of: " + e); continue; } } throw lastException; }