How to detect the error raised on a particular codeline?
- by infant programmer
[Please edit the title if you find its not good enough]
I have code which triggers XSL-transformation:
objMemoryStream = new MemoryStream();
xslTransform = new XslCompiledTransform();
xpathXmlOrig = new XPathDocument("E:\\xslt error\\Simulation_of_error\\input.xml");
xslSettings = new XsltSettings();
xslSettings.EnableScript = true;
xslTransform.Load(strXmlQueryTransformPath, xslSettings, new XmlUrlResolver());
xslTransform.Transform(xpathXmlOrig, null, objMemoryStream);
objMemoryStream.Position = 0;
StreamReader objStreamReader = new StreamReader(objMemoryStream);
The method xslTransform.Load(strXmlQueryTransformPath, xslSettings, new XmlUrlResolver()); is a victim, which fails some times due to some time-out issue.
I want to detect the failure of this codeline and execute again until it successfully executes!
I tried using "TRY CATCH and WHILE methods":
bool flag = true;
do
{
try
{
xslTransform.Load(strXmlQueryTransformPath, xslSettings, new XmlUrlResolver());
flag = false;
}
catch
{
flag = true;
}
} while (flag);
but the problem is "error is getting logged in the log file", Well. The whole code is under one more try statement, which I suspect is writing to log. Which is what I don't want... I don't want end user to know about the failure of this codeline.
Is there anyway to get it done?