Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've just made some experiments with <code>InetAddress</code> class and also read its javadocs.</p> <p>After the first touch I can tell that I get <code>UnknownHostException</code> in 2 cases: either when I pass illegal formated string (like <code>http://stackoverflow.com</code> instead of <code>stackoverflow.com</code>) or when I pass URL that cannot be resolved in browser too (i.e. something like <code>aosjdfk23423.com</code>).</p> <p>Both cases are documented in javadocs (although it's not explicitely said anywhere anything strict about the parameter format). Here are related javadocs parts:</p> <blockquote> <p>The host name can either be a machine name, such as <code>java.sun.com</code>, or a textual representation of its IP address. If a literal IP address is supplied, only the validity of the address format is checked.</p> </blockquote> <p><p></p> <blockquote> <p>@exception UnknownHostException if no IP address for the <code>host</code> could be found, or if a scope_id was specified for a global IPv6 address.</p> </blockquote> <p>Summary:</p> <p>this works:</p> <pre><code>InetAddress.getByName("google.com"); InetAddress.getByName("74.125.87.99"); </code></pre> <p>and this throws <code>UnknownHostException</code>:</p> <pre><code>InetAddress.getByName("http://google.com"); InetAddress.getByName("unexistingresourse234234.com"); </code></pre> <p>UPD (as an answer to the comments: there should be something like this:</p> <pre><code>List&lt;String&gt; hosts = getPossibleHosts(); //these are all hosts you want to transform into inet addresses final List&lt;InetAddress&gt; inetAddresses = new LinkedList&lt;InetAddress&gt;(); final List&lt;String&gt; badHosts = new LinkedList&lt;String&gt;(); for(String host : hosts) { try { inetAddresses.add(InetAddress.getByName(host)); } catch (UnknownHostException e) { badHosts.add(host); } } </code></pre> <p>After that you can process both lists as you wish. But it's a mistake to try to put them in the same list - they are not same. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload