
D.H.J. Takken schrieb am 05.12.2014 um 15:31:
I use etree.xmlfile and a coroutine to generate XML into a file-like object that does post-processing on the XML data. Now, if I use the send() method to produce invalid XML data, the post-processor throws an exception.
Here, I see a little problem: No matter what exception is thrown by the post-processor, the send() method always generates a generic IO exception. Apparently, lxml catches any exception thrown by the file-like object and produces a generic IO exception in stead. This means that there is no way to know what exactly went wrong in the post-processor. That information is lost.
Inside the coroutine, I *do* get the original exception from the post-processor, but doing the error handling there is kind of ugly.
Is there a better way to solve this problem?
Could you provide some example code that illustrates this, and mark the places where the exception is available and where it's lost? Is it possible that the output stream is closed (or otherwise unwritable) when your post-processing exception is raised, so that an actual IOError is raised when trying to write out the closing tags, which then shadows the original exception? I assume you're using Python 2.x, which cannot chain exceptions? Stefan