似乎不能处理XMLException? [英] Can't seem to handle XMLException?
问题描述
我在我们的一个项目网页中有以下代码:
XmlDocument xDoc = new XmlDocument();
xDoc.Load(File.FullName);
//通过此队列文件中的每个打印批处理
try
{
XmlNodeList nodeList = xDoc.SelectNodes(Reports / PrintBatch);
foreach(nodeList中的XmlNode printBatch)// xDoc.SelectNodes(Reports / PrintBatch)
{
PrintBatch batch = new PrintBatch();
batch.LoadBatch(printBatch,File.Extension);
this.AddBatch(batch);
}
}
catch(XmlException e)
{
//此报告加载错误!
Console.WriteLine(e.Message);
}
它基本上需要一个xml批处理文件,并将其加载为对象,准备就绪要处理。
直到最近,发现其中一个XML文件包含一个空字符(在XML中无效)。 >
当尝试处理这个dudd文件时,我们得到以下异常:
alt text http://blog.ianmellor.co.uk/images/xml_err.jpg
Ok到目前为止..但是当我们尝试继续或过渡时,我希望它流入catch块。
但是,它不是;我们只得到死亡的红屏:
替代文字http://blog.ianmellor.co.uk/images/xml_err2.jpg
我做错了什么?
这是因为你没有写过
xDoc。负载(File.FullName); try块内的
这就是为什么没有处理例外。
I have the following code in one of our projects webpages:
XmlDocument xDoc = new XmlDocument();
xDoc.Load(File.FullName);
//work through each print batch in this queue file
try
{
XmlNodeList nodeList = xDoc.SelectNodes("Reports/PrintBatch");
foreach (XmlNode printBatch in nodeList)//xDoc.SelectNodes("Reports/PrintBatch"))
{
PrintBatch batch = new PrintBatch();
batch.LoadBatch(printBatch, File.Extension);
this.AddBatch(batch);
}
}
catch (XmlException e)
{
//this report had an error loading!
Console.WriteLine(e.Message);
}
It basically takes an xml batch file and loads it up as an object, ready to be processed.
It's been working fine, until recently when one of the XML files was found to contain a null character (which is invalid in XML).
When it tries to process this "dudd" file, we get the following exception:
alt text http://blog.ianmellor.co.uk/images/xml_err.jpg
Ok so far.. but when we then try to "continue" or "step over", I expect it to flow into the catch block. However, it doesn't; we simply get the red screen of death:
alt text http://blog.ianmellor.co.uk/images/xml_err2.jpg
What am I doing wrong?
It is because you have not written
xDoc.Load(File.FullName);
inside the try block. That is the reason why the exception was not handled.
这篇关于似乎不能处理XMLException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!