What is the proper way to catch and identify the HttpRequestException “The remote name could not be resolved: 'www.example.com'”?
What is the proper way to catch and identify the HttpRequestException “The remote name could not be resolved: 'www.example.com'”? I want to be able to catch and identify the exceptions that belong to this specific type and then return a suitable error message. What is the proper way to do that in a catch block? 2 Answers 2 The exception you need to catch is an HttpRequestException specifically with an InnerException that is a WebException and has a Status property with a value of WebExceptionStatus.NameResolutionFailure . HttpRequestException InnerException WebException Status WebExceptionStatus.NameResolutionFailure Fortunately, using C# 6.0 exception filters, it's now easy to catch only an exception that fulfills these specific criteria: var hc=new HttpClient(); try { (await hc.GetStringAsync("https://www.googggle.com")); } catch(HttpRequestException ex) when ((ex....
