Well, apparently, your UnknownHostException wrapped in some other exception. In other words, some of the code above catches an UnknownHostException and throws:
throw new SomeOtherException("Custom Message", unknownHostEx);
Print e.getClass() to see which exception it wraps. You can also try:
if(e.getCause() != null && e.getCause() instanceof UnknownHostException)
but it is ugly.
By the way, you should avoid using instanceof and catch define the <exception> of the exception itself (but this will not help in your case):
catch (java.net.UnknownHostException e) { System.out.println("Unknown Host Ex"); } catch (Exception e) { System.out.println("OTHER ERROR"); }
source share