Calling method from catch method doesn't work



I'm trying to call a method from a catch block but the xmlnode inside the method doesn't seem to work. I'm getting a null. If I call the same method from the try block it works.



var doc = new XmlDocument();

try
{

doc.Load(f.FullPath);
// do some work

}

catch (Exception e)
{
if (e is XMLException)
{
checkXML(ref doc);
}

public void checkXML(ref XmlDocument doc)
{

XmlNode xn = doc.SelectSingleNode("/BroadcastMonitor/Current");
xn["name1"].InnerText = SecurityElement.Escape(xn["name1"].InnerText);
xn["name2"].InnerText = SecurityElement.Escape(xn["name2"].InnerText); ;


}


Now when the catch block calls method 'checkXML', i get xn as null. But if I execute the same from the 'try' block just to check, 'xn' has a value. 'doc' too has a value regardless of when called try or from catch block.


Why is this happening? Please help me understand.


Thank you.


No comments:

Post a Comment