I’m trying to print something when an exception occurs in my android program, in my socket’s exception block.
But, even if I give an invalid ip address, my Exception is not being called.
try{
SocketAddress socketAddress = new InetSocketAddress("78.137.18" , 8364);
}
catch (Exception e)
{
System.out.println("ERROR");
}
That is actually a valid IP address.
The constructor for
InetSocketAddresswill also accept hostnames.If you want to specifically reject those addresses (but are you sure?) then you will have to write code to check the address string, maybe with a regex.