I have found example of how to treat WebException on GetResponse call, and puzzling on how the response can be extracted from WebException Response. The second puzzle is why null response is treated as throw; Any suggestion?
HttpWebResponse response = null;
try
{
response = (HttpWebResponse) request.GetResponse();
}
catch (WebException ex)
{
response = (HttpWebResponse)ex.Response;
if (null == response)
{
throw;
}
}
The response should never be
null– in this case the author is saying theWebExceptioncan’t be handled within this exception handler and it is just propagated up.Still this exception handling is not ideal – you probably want to know why an exception occurred, i.e.: