2

I have a simple part of a code:

try
{
    this.client.ExecuteAsync<Answer>(request, response =>
        {
            if (response.ResponseStatus == ResponseStatus.Completed)
                callback(response.Data);
            ...
        });
}
catch (WebException ex) {...}

and it throws NullReferenceException in the if line, because the response is null. What can I do to get a message about server down?

hydeparkk
  • 62
  • 1
  • 7

1 Answers1

1

Just add in a null check for your response:

try
{
    this.client.ExecuteAsync<Answer>(request, response =>
        {
            if (response != null && response.ResponseStatus == ResponseStatus.Completed)
                callback(response.Data);
            else
            {
               // add logic here to handle bad case
            }
        });
}
catch (WebException ex) {...}
gleng
  • 6,185
  • 4
  • 21
  • 35