Handling errors

This commit is contained in:
AgCaliva
2023-05-21 01:39:39 -03:00
parent c752d0cdf9
commit d7e5b9dc5a
2 changed files with 28 additions and 14 deletions

View File

@@ -330,12 +330,25 @@ void Base::XMLReader::readFiles(zipios::ZipInputStream &zipstream) const
// no file name for the current entry in the zip was registered.
if (jt != FileList.end()) {
try {
Base::Reader reader(zipstream, jt->FileName, FileVersion);
jt->Object->RestoreDocFile(reader);
if (reader.getLocalReader())
reader.getLocalReader()->readFiles(zipstream);
}
catch(...) {
Base::Reader reader(zipstream, jt->FileName, FileVersion);
try{
jt->Object->RestoreDocFile(reader);
}catch (const Base::XMLParseException& e) {
//For some reason catching this error in RestoreDocFile(reader) its working but
//still need to catch it here again. Im not sure how its that possible since its from a constructor.
//It comes from trying to read "ProjectUnitSystem" from GuiDocument.xml and reaching EndDocument
//because was not found.
//I dont think EndDocument should throw error anyway.
if(e.getMessage() != "End of document reached"){
throw;
}
}
if (reader.getLocalReader())
reader.getLocalReader()->readFiles(zipstream);
}catch(...) {
// For any exception we just continue with the next file.
// It doesn't matter if the last reader has read more or
// less data than the file size would allow.

View File

@@ -1480,14 +1480,15 @@ void Document::RestoreDocFile(Base::Reader &reader)
Base::Console().Error("%s\n", e.what());
}
}
try{
localreader->readElement("ProjectUnitSystem");
int US = localreader->getAttributeAsInteger("US");
int ignore = localreader->getAttributeAsInteger("ignore");
d->projectUnitSystem = US;
d->projectUnitSystemIgnore = ignore;
}catch (const Base::XMLParseException& e) {
Base::Console().Error("ProjectUnitSystem not found\n");
try{
localreader->readElement("ProjectUnitSystem");
int US = localreader->getAttributeAsInteger("US");
int ignore = localreader->getAttributeAsInteger("ignore");
d->projectUnitSystem = US;
d->projectUnitSystemIgnore = ignore;
}catch (const Base::XMLParseException& e) {
Base::Console().Warning("ProjectUnitSystem not found: %s\n", e.getMessage().c_str());
}
}