I've seen such block of code, and cant understand why finally block is needed in such cases.
You cannot understand it because the finally block is not needed. It should be removed.
do local variables to be nulled/disposed in methods?
Nulled? No. Disposed? Yes. A local holding a disposable that is not owned by code outside the method should be disposed as soon as possible. Normally you would use a using
statement to do that.
A question you did not ask:
Is there anything else wrong with this method?
Yes. Catching and then throwing again is a worst practice because doing so mutates the stack trace of the exception. This practice makes it harder for the developer to track down the cause of the exception because the trace will be truncated at ParseNewsXMLAndPopulateNewsList, and not include the information about the actual trace of the method that threw.
If you have to catch and rethrow, the best practice is
try { whatever }
catch (Exception ex)
{
// something here -- log the exception, say
throw;
}
A bare "throw" means "rethrow the current exception without modification".
Anything else?
I don't like rewriting debugged, working code for no reason. But I do note that the method could be much, much shorter. You have ten statements where three would do nicely:
private void ParseNewsXMLAndPopulateNewsList(string xmlToParse)
{
XmlDocument rawXmlDoc = new XmlDocument();
rawXmlDoc.LoadXml(xmlToParse);
_SmthGlobalObject.AddRange(
rawXmlDoc
.SelectNodes(@"//event")
.Select(e => e.SelectSingleNode("title").InnerText));
}
That seems much clearer and more straightforward to me. What are we doing? Loading a document, extracting the events, adding their titles to a list. So do exactly that.