]> git.mxchange.org Git - simgear.git/commitdiff
Better XML error catching, proposed by Richard Harrison.
authorehofman <ehofman>
Thu, 15 Sep 2005 16:54:27 +0000 (16:54 +0000)
committerehofman <ehofman>
Thu, 15 Sep 2005 16:54:27 +0000 (16:54 +0000)
simgear/xml/easyxml.cxx

index 3636fa9d3fe46feef6eda5ac48fdc59674d9983d..dbebf0cae79ccb9861490c56a4a456ad581da0ea 100644 (file)
@@ -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);