The UnresolvedAddressException
is not a subclass of IOException
, which is why you won't catch it if it's thrown.
UnresolvedAddressException
is a subclass of IllegalArgumentException
, as shown here, so try catching:
UnresolvedAddressException
itself, as it's always better practice to catch the most specific exception type firstException
if you don't really care about the exception you catch, as you can always halt the program or work around that
Edit: You probably missed that exception because the compiler did not force you to catch it. That is because UnresolvedAddressException
is derived from RuntimeException
, the type of exceptions which smack you in the head during execution. The exceptions not derived from RuntimeException
, such as IOException
, have to be caught, which is why your compiler probably told you to wrap your code into a try-catch block in the first place.