How to detect the error raised on a particular codeline?
Posted
by infant programmer
on Stack Overflow
See other posts from Stack Overflow
or by infant programmer
Published on 2010-05-18T17:11:14Z
Indexed on
2010/05/18
20:50 UTC
Read the original article
Hit count: 311
[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?
© Stack Overflow or respective owner