I am working on a Winforms application and using C# as the development language. In one place I need to send a request to a URL and receive the feedback.
I use my code within a try catch block and I catch the WebException. I noticed WebException occures due to 2 reasons.
(1) when the URL I entered is wrong(A url that does not exist)
(2) When there is no internet connection
So is that okay If I catch the WebException in a situation where the URL is correct, to check that the local machine does not have internet connection. (I need to check that the internet connection exists or not to continue the next step)
Can anyone confirm that my suggestion is correct or if wrong why? Thanks inadvance
You can’t check for Internet connection by trying to connect to an URL. You can’t tell between a bad connection or the server not available.
There is a win32 API in wininet – see check whether Internet connection is available with C#