I am reading a very large XML file, which I have to read as a stream, like so:
public IEnumerable<something> GetStuff()
{
foreach(var gzipStream in GetGZips())
{
using (var reader = XmlReader.Create(gzipStream, new XmlReaderSettings{ CheckCharacters = false }))
{
reader.MoveToContent();
while (reader.Read()) //<-- Exception here
{
//Do stuff
yield return something;
}
}
}
}
I get an invalid char exception, part-way through the processing:
' ', hexadecimal value 0x19, is an invalid character. Line 655, position 45.
Given you're not allowed to yield return inside a try-catch - what is a nice way to simply abort the processing of the current Xml doc (and completing the Enumeration), in the case of an error?
try/finally is no good - as the exception breaks the processing of the whole IEnumerable.
I'm not able to perform any pre-processing on the files.