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?