c# - WebException Response attribute returns null -


i'm scanning single url has many paths example: http://url.com/path1 1000. webexception in catch block, throw nullreferenceexception error if don't use line
if (x.status == webexceptionstatus.protocolerror && x.response != null)

so question this: code below fix error or ignore it?

error don't have specific path error random http://url.com/path10 or other link :)

catch (webexception x) {     if (x.status == webexceptionstatus.protocolerror && x.response != null)     {         httpwebresponse response = (httpwebresponse)x.response;         if (response.statuscode == httpstatuscode.notfound)         {            listbox3.items.add(listbox1.items[i].tostring());         }     } } 

according documentation webexception.response property

if response available internet resource, webresponse instance contains error response internet resource; otherwise, null.

so, if understand question correctly, is necessary test webexception.response null, meaning code correctly avoids nullreferenceexception rather 'ignoring' it.

hope helps.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -