From 9dfd6970f118884ed2e9811f4f8d238c6bbf430a Mon Sep 17 00:00:00 2001 From: ehofman Date: Thu, 15 Sep 2005 16:54:27 +0000 Subject: [PATCH] Better XML error catching, proposed by Richard Harrison. --- simgear/xml/easyxml.cxx | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/simgear/xml/easyxml.cxx b/simgear/xml/easyxml.cxx index 3636fa9d..dbebf0ca 100644 --- a/simgear/xml/easyxml.cxx +++ b/simgear/xml/easyxml.cxx @@ -220,34 +220,37 @@ readXML (istream &input, XMLVisitor &visitor, const string &path) // FIXME: get proper error string from system if (!input.good()) { - XML_ParserFree(parser); - throw sg_io_exception("Problem reading file", + sg_io_exception ex ("Problem reading file", sg_location(path, XML_GetCurrentLineNumber(parser), XML_GetCurrentColumnNumber(parser)), "SimGear XML Parser"); + XML_ParserFree(parser); + throw ex; } input.read(buf,16384); if (!XML_Parse(parser, buf, input.gcount(), false)) { - XML_ParserFree(parser); - throw sg_io_exception(XML_ErrorString(XML_GetErrorCode(parser)), + sg_io_exception ex (XML_ErrorString(XML_GetErrorCode(parser)), sg_location(path, XML_GetCurrentLineNumber(parser), XML_GetCurrentColumnNumber(parser)), "SimGear XML Parser"); + XML_ParserFree(parser); + throw ex; } } // Verify end of document. if (!XML_Parse(parser, buf, 0, true)) { - XML_ParserFree(parser); - throw sg_io_exception(XML_ErrorString(XML_GetErrorCode(parser)), + sg_io_exception ex (XML_ErrorString(XML_GetErrorCode(parser)), sg_location(path, XML_GetCurrentLineNumber(parser), XML_GetCurrentColumnNumber(parser)), "SimGear XML Parser"); + XML_ParserFree(parser); + throw ex; } XML_ParserFree(parser); @@ -286,12 +289,13 @@ readXML (const char *buf, const int size, XMLVisitor &visitor) visitor.startXML(); if (!XML_Parse(parser, buf, size, false)) { - XML_ParserFree(parser); - throw sg_io_exception(XML_ErrorString(XML_GetErrorCode(parser)), + sg_io_exception ex (XML_ErrorString(XML_GetErrorCode(parser)), sg_location("In-memory XML buffer", XML_GetCurrentLineNumber(parser), XML_GetCurrentColumnNumber(parser)), "SimGear XML Parser"); + XML_ParserFree(parser); + throw ex; } XML_ParserFree(parser); -- 2.39.5