Suppress reports on some common exception throws

This commit is contained in:
James Turner
2021-02-19 17:39:14 +00:00
parent e3f4c44685
commit 041c247c0f
3 changed files with 49 additions and 41 deletions

View File

@@ -552,10 +552,7 @@ bool SGBinObject::read_bin( const SGPath& file ) {
withGZ.concat(".gz");
fp = gzFileFromSGPath(withGZ, "rb");
if (fp == nullptr) {
SG_LOG( SG_EVENT, SG_ALERT,
"ERROR: opening " << file << " or " << withGZ << " for reading!");
throw sg_io_exception("Error opening for reading (and .gz)", sg_location(file));
throw sg_io_exception("Error opening for reading (and .gz)", sg_location(file), {}, false);
}
}
@@ -569,7 +566,8 @@ bool SGBinObject::read_bin( const SGPath& file ) {
int code = 0;
const char* gzErrorString = gzerror(fp, &code);
gzclose(fp);
throw sg_io_exception("Unable to read BTG header: " + string{gzErrorString} + ", code =" + std::to_string(code), sg_location(file));
throw sg_io_exception("Unable to read BTG header: " + string{gzErrorString} + ", code =" + std::to_string(code),
sg_location(file), {}, false);
}
if ( ((header & 0xFF000000) >> 24) == 'S' &&
@@ -580,7 +578,7 @@ bool SGBinObject::read_bin( const SGPath& file ) {
} else {
// close the file before we return
gzclose(fp);
throw sg_io_exception("Bad BTG magic/version", sg_location(file));
throw sg_io_exception("Bad BTG magic/version", sg_location(file), {}, false);
}
// read creation time
@@ -617,7 +615,10 @@ bool SGBinObject::read_bin( const SGPath& file ) {
SG_LOG(SG_IO, SG_DEBUG, "SGBinObject::read_bin Total objects to read = " << nobjects);
if ( sgReadError() ) {
throw sg_io_exception("Error reading BTG file header", sg_location(file));
int code = 0;
const char* gzErrorString = gzerror(fp, &code);
throw sg_io_exception("Error reading BTG file header:" + string{gzErrorString} + ", code =" + std::to_string(code),
sg_location(file), {}, false);
}
// read in objects
@@ -805,7 +806,10 @@ bool SGBinObject::read_bin( const SGPath& file ) {
}
if ( sgReadError() ) {
throw sg_io_exception("Error while reading object", sg_location(file, i));
int code = 0;
const char* gzErrorString = gzerror(fp, &code);
throw sg_io_exception("Error reading BTG object:" + string{gzErrorString} + ", code =" + std::to_string(code),
sg_location(file, i), {}, false);
}
}

View File

@@ -75,13 +75,13 @@ BuilderException::BuilderException()
}
BuilderException::BuilderException(const char* message, const char* origin)
: sg_exception(message, origin)
: sg_exception(message, origin, {}, false)
{
}
BuilderException::BuilderException(const std::string& message,
const std::string& origin)
: sg_exception(message, origin)
: sg_exception(message, origin, {}, false)
{
}

View File

@@ -244,40 +244,43 @@ readXML (istream &input, XMLVisitor &visitor, const string &path)
// FIXME: get proper error string from system
if (!input.good()) {
sg_io_exception ex ("Problem reading file",
sg_location(path,
XML_GetCurrentLineNumber(parser),
XML_GetCurrentColumnNumber(parser)),
"SimGear XML Parser");
visitor.setParser(0);
XML_ParserFree(parser);
throw ex;
sg_io_exception ex("Problem reading file",
sg_location(path,
XML_GetCurrentLineNumber(parser),
XML_GetCurrentColumnNumber(parser)),
"SimGear XML Parser",
false /* don't report */);
visitor.setParser(0);
XML_ParserFree(parser);
throw ex;
}
input.read(buf,16384);
if (!XML_Parse(parser, buf, input.gcount(), false)) {
sg_io_exception ex (XML_ErrorString(XML_GetErrorCode(parser)),
sg_location(path,
XML_GetCurrentLineNumber(parser),
XML_GetCurrentColumnNumber(parser)),
"SimGear XML Parser");
visitor.setParser(0);
XML_ParserFree(parser);
throw ex;
sg_io_exception ex(XML_ErrorString(XML_GetErrorCode(parser)),
sg_location(path,
XML_GetCurrentLineNumber(parser),
XML_GetCurrentColumnNumber(parser)),
"SimGear XML Parser",
false /* don't report */);
visitor.setParser(0);
XML_ParserFree(parser);
throw ex;
}
}
// Verify end of document.
if (!XML_Parse(parser, buf, 0, true)) {
sg_io_exception ex (XML_ErrorString(XML_GetErrorCode(parser)),
sg_location(path,
XML_GetCurrentLineNumber(parser),
XML_GetCurrentColumnNumber(parser)),
"SimGear XML Parser");
visitor.setParser(0);
XML_ParserFree(parser);
throw ex;
sg_io_exception ex(XML_ErrorString(XML_GetErrorCode(parser)),
sg_location(path,
XML_GetCurrentLineNumber(parser),
XML_GetCurrentColumnNumber(parser)),
"SimGear XML Parser",
false /* don't report */);
visitor.setParser(0);
XML_ParserFree(parser);
throw ex;
}
visitor.setParser(0);
@@ -300,8 +303,8 @@ readXML (const SGPath &path, XMLVisitor &visitor)
throw;
}
} else {
throw sg_io_exception("Failed to open file", sg_location(path),
"SimGear XML Parser");
throw sg_io_exception("Failed to open file", sg_location(path),
"SimGear XML Parser", false /* don't report */);
}
input.close();
}
@@ -318,11 +321,12 @@ readXML (const char *buf, const int size, XMLVisitor &visitor)
visitor.startXML();
if (!XML_Parse(parser, buf, size, false)) {
sg_io_exception ex (XML_ErrorString(XML_GetErrorCode(parser)),
sg_location("In-memory XML buffer",
XML_GetCurrentLineNumber(parser),
XML_GetCurrentColumnNumber(parser)),
"SimGear XML 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",
false /* don't report */);
XML_ParserFree(parser);
throw ex;
}