Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internet Connection Error

I have an Android application which connects to the Internet. I am trapping all the possible scenarios for the connection and notice that when I don't have an Internet connection, an UnknownHostException is thrown. I am a bit confused here since getting an UnknownHostException will mean that the application was able to connect to the Internet but wasn't able to find the given URL.

Am I getting the right Exception? Could you explain why am I getting an UnknownHostException in this?

Also, can you tell the specific Exceptions for these scenarios:

  • When there is no Internet connection.
  • When the URL cannot be found.
  • When the request timed out.
  • When the website is down.
  • When access is denied.

I would also appreciate it if you could give me more scenarios and Exceptions. I have to trap all the possible connections and display the most appropriate message depending on the type of connection Error.

like image 683
Arci Avatar asked Dec 20 '11 09:12

Arci


People also ask

Why does it keep saying Internet connection failed?

There could be any number of reasons you can't reach the internet: The firewall might be malfunctioning, the wireless signal might be blocked or too weak to use, the router might be experiencing issues, there could be IP address conflicts . . . the list goes on.

Why is my WiFi connected but no internet?

WiFi connected but no Internet: Start with the router If the Internet works fine on other devices, the problem lies with your device and its WiFi adapter. On the other hand, if the Internet doesn't work on other devices too, then the problem is most likely with the router or the Internet connection itself.


1 Answers

getting an UnknownHostException will mean that the application was able to connect to the Internet

No it doesn't. It means the application was unable to resolve the host name. That could be because the host name doesn't exist, or because it was unable to connect to the Internet to resolve it.

When there is no Internet connection.

No specific exception. "There is no Internet connection" doesn't have a well-defined meaning. The condition resolves to one of the other failure modes below.

When the URL cannot be found.

If the host cannot be found, UnknownHostException. If the content part of the URL cannot be found, HTTP 404.

When the request timed out.

ConnectException with 'connection timed out' as the message, or SocketTimeoutException if it's a read timeout.

When the website is down.

ConnectException with 'connection refused' as the message.

When access is denied.

HTTP 403.

like image 70
user207421 Avatar answered Oct 11 '22 14:10

user207421