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.