I have a method that returns a list from a HTML page:
private List<HtmlNodes> GetRelevantNodes(HtmlDocument aHtmlDoc, string aID)
{
List<HtmlNode> nodes = new List<HtmlNode>();
HtmlNode currentDiv = aHtmlDoc.GetElementbyId(aID);
if (currentDiv == null)
return null;
else
//Do stuff - fill the nodes list...
return nodes;
}
I'm not sure what to do with the return value in case the currentDiv
variable is null
. Obviously I can't continue the method regularly and I need to return from this method with some indication that there's no such div
.
If I return null
and handle it up the stack it'll work fine but it's less readable code (at list in my opinion... don't you think?). Another thing I can add is an out string
with the error message and maybe use it later for the end user output but that still doesn't solve my readable problem.
I'd be happy to hear your ideas and advice.