Harinder
Harinder

Reputation: 11944

Android not throwing SocketException?

Why doesn't Android throw a SocketException when the socket is closed?

I get an IOException if there is no permission added in the manifest file for Internet but when I grant it the Internet permission and check my program it gets stuck at

Socket obj=new Socket("*****",3000);

if the socket is closed? Why is that? It should not keep waiting for the socket to open instead throw an exception

try {
    Socket obj=new Socket("*****",3000);
} catch (UnknownHostException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

Upvotes: 2

Views: 278

Answers (1)

Ravi Vyas
Ravi Vyas

Reputation: 12375

SocketException is a subclass of IOException, so the exception is being caught by your second catch clause which is the reason you don't see it.

Upvotes: 2

Related Questions