1

I have a segment of code that checks to see if a site is available

 public static bool IsReachableUri(string uriInput)
    {
        bool testStatus;

        WebResponse response;
        try
        {
            WebRequest request = WebRequest.Create (uriInput);
            request.Timeout = 2000; // 2 Sec
            response = request.GetResponse();
            testStatus = true; // Uri does exist                 
            response.Close();
        }
        catch (Exception ex)
        {
            testStatus = false; // Uri does not exist
        }

        return testStatus;
    }

However, in some instances I am getting this error, and it appears that the try-catch has no effect.

Crashed: Threadpool worker EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000

23. Crashed: Threadpool worker System_Net_WebConnection_InitRead_object (WebConnection.cs:579)

System_Net_WebConnectionStream_Close (WebConnectionStream.cs:805) System_Net_WebConnectionStream_Close (WebConnectionStream.cs:805) System_Net_HttpWebRequest_Abort (HttpWebRequest.cs:1092) System_Net_HttpWebRequest_EndGetResponse_System_IAsyncResult (HttpWebRequest.cs:1019) System_Net_HttpWebRequest_GetResponse (HttpWebRequest.cs:1037) Reachability_IsReachableUri_string (:1)

Looking at other StackOverFlow threads, I am interpreting that in native Objective C, the EXC_BAD_ACCESS KERN_INVALID_ADDRESS is not a catch-able error.

Is there a better way to handle this response?

Community
  • 1
  • 1
Ben Butzer
  • 915
  • 10
  • 24
  • I'm having a similar issue where sometimes my code crashes in the same way when calling `collection.ElementAt(index)`... I know for sure that the collection is not null and that index is valid because I've already checked the number of objects in the collection. Can't find any reason it should be crashing and can't catch it. So frustrating. If you find anything, please share. – Brandon Rader Aug 29 '17 at 16:41
  • For why the try/catch block doesn't help here, see [this nice explanation](https://stackoverflow.com/a/24589879/3265733). – Matteo Mecucci Jul 20 '18 at 13:27

0 Answers0