gpt4 book ai didi

c# - 似乎无法处理 XMLException?

转载 作者:数据小太阳 更新时间:2023-10-29 01:55:47 26 4
gpt4 key购买 nike

我在我们的一个项目网页中有以下代码:

            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);
}

它基本上需要一个 xml 批处理文件并将其加载为一个对象,准备好进行处理。

它一直运行良好,直到最近发现其中一个 XML 文件包含空字符(这在 XML 中是无效的)。

当它试图处理这个“dudd”文件时,我们得到以下异常:

alt text http://blog.ianmellor.co.uk/images/xml_err.jpg

到此为止......但是当我们尝试“继续”或“跳过”时,我希望它流入 catch block 。然而,事实并非如此;我们只是得到了死亡的红屏:

alt text http://blog.ianmellor.co.uk/images/xml_err2.jpg

我做错了什么?

最佳答案

那是因为你没有写

xDoc.Load(File.FullName);

在 try block 中。这就是未处理异常的原因。

关于c# - 似乎无法处理 XMLException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1404447/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com