some additions to pR 1794:

add a special XMLAttributeError class to indicate an error when accessing a missing attribute
in PropertyContainer::Restore make error handling more flexible
This commit is contained in:
wmayer
2018-11-19 19:07:56 +01:00
parent 7216dba2f3
commit ddb20468ad
7 changed files with 71 additions and 19 deletions

View File

@@ -1448,6 +1448,7 @@ void Application::initTypes(void)
new ExceptionProducer<Base::AbortException>;
new ExceptionProducer<Base::XMLBaseException>;
new ExceptionProducer<Base::XMLParseException>;
new ExceptionProducer<Base::XMLAttributeError>;
new ExceptionProducer<Base::FileException>;
new ExceptionProducer<Base::FileSystemError>;
new ExceptionProducer<Base::BadFormatError>;

View File

@@ -1581,7 +1581,7 @@ Document::readObjects(Base::XMLReader& reader)
pObj->setStatus(ObjectStatus::Restore, false);
if(reader.testStatus(Base::XMLReader::ReaderStatus::PartialRestoreInDocumentObject)) {
if (reader.testStatus(Base::XMLReader::ReaderStatus::PartialRestoreInDocumentObject)) {
Base::Console().Error("Object \"%s\" was subject to a partial restore. As a result geometry may have changed or be incomplete.\n",name.c_str());
reader.clearPartialRestoreDocumentObject();
}
@@ -1882,7 +1882,7 @@ void Document::restore (void)
GetApplication().signalFinishRestoreDocument(*this);
setStatus(Document::Restoring, false);
if(reader.testStatus(Base::XMLReader::ReaderStatus::PartialRestore)) {
if (reader.testStatus(Base::XMLReader::ReaderStatus::PartialRestore)) {
setStatus(Document::PartialRestore, true);
Base::Console().Error("There were errors while loading the file. Some data might have been modified or not recovered at all. Look above for more specific information about the objects involved.\n");
}

View File

@@ -276,13 +276,7 @@ void PropertyContainer::Restore(Base::XMLReader &reader)
try {
// name and type match
if (prop && strcmp(prop->getTypeId().getName(), TypeName.c_str()) == 0) {
prop->Restore(reader);
if(reader.testStatus(Base::XMLReader::ReaderStatus::PartialRestoreInProperty)) {
Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",PropName.c_str(),TypeName.c_str());
reader.clearPartialRestoreProperty();
}
prop->Restore(reader);
}
// name matches but not the type
else if (prop) {
@@ -293,10 +287,20 @@ void PropertyContainer::Restore(Base::XMLReader &reader)
else {
handleChangedPropertyName(reader, TypeName.c_str(), PropName.c_str());
}
if (reader.testStatus(Base::XMLReader::ReaderStatus::PartialRestoreInProperty)) {
Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",PropName.c_str(),TypeName.c_str());
reader.clearPartialRestoreProperty();
}
}
catch (const Base::XMLParseException&) {
throw; // re-throw
}
catch (const Base::RestoreError &) {
reader.setPartialRestore(true);
reader.clearPartialRestoreProperty();
Base::Console().Error("Property %s of type %s was subject to a partial restore.\n",PropName.c_str(),TypeName.c_str());
}
catch (const Base::Exception &e) {
Base::Console().Error("%s\n", e.what());
}

View File

@@ -210,14 +210,13 @@ XMLBaseException::XMLBaseException(const XMLBaseException &inst)
// ---------------------------------------------------------
XMLParseException::XMLParseException(const char * sMessage)
: Exception(sMessage)
: XMLBaseException(sMessage)
{
}
XMLParseException::XMLParseException(const std::string& sMessage)
: Exception(sMessage)
: XMLBaseException(sMessage)
{
}
@@ -227,13 +226,40 @@ XMLParseException::XMLParseException()
}
XMLParseException::XMLParseException(const XMLParseException &inst)
: Exception(inst)
: XMLBaseException(inst)
{
}
const char* XMLParseException::what() const throw()
{
return Exception::what();
return XMLBaseException::what();
}
// ---------------------------------------------------------
XMLAttributeError::XMLAttributeError(const char * sMessage)
: XMLBaseException(sMessage)
{
}
XMLAttributeError::XMLAttributeError(const std::string& sMessage)
: XMLBaseException(sMessage)
{
}
XMLAttributeError::XMLAttributeError()
{
_sErrMsg = "XML attribute error";
}
XMLAttributeError::XMLAttributeError(const XMLAttributeError &inst)
: XMLBaseException(inst)
{
}
const char* XMLAttributeError::what() const throw()
{
return XMLBaseException::what();
}
// ---------------------------------------------------------
@@ -827,7 +853,6 @@ CADKernelError::CADKernelError(const CADKernelError &inst)
}
// ---------------------------------------------------------
// ---------------------------------------------------------
RestoreError::RestoreError()

View File

@@ -179,7 +179,7 @@ public:
* The XMLParseException is thrown if parsing an XML failed.
* @author Werner Mayer
*/
class BaseExport XMLParseException : public Exception
class BaseExport XMLParseException : public XMLBaseException
{
public:
/// Construction
@@ -197,6 +197,28 @@ public:
virtual const char* what() const throw();
};
/**
* The XMLAttributeError is thrown if a requested attribute doesn't exist.
* @author Werner Mayer
*/
class BaseExport XMLAttributeError : public XMLBaseException
{
public:
/// Construction
XMLAttributeError(const char * sMessage);
/// Construction
XMLAttributeError(const std::string& sMessage);
/// Construction
XMLAttributeError();
/// Construction
XMLAttributeError(const XMLAttributeError &inst);
/// Destruction
virtual ~XMLAttributeError() throw() {}
/// Description of the exception
virtual const char* what() const throw();
};
/** File exception handling class
* This class is specialized to go with exception thrown in case of File IO Problems.
* @author Juergen Riegel

View File

@@ -175,8 +175,8 @@ const char* Base::XMLReader::getAttribute (const char* AttrName) const
else {
// wrong name, use hasAttribute if not sure!
std::ostringstream msg;
msg << "Attribute: \"" << AttrName << "\" not found";
THROWM(Base::AttributeError, msg.str());
msg << "XML Attribute: \"" << AttrName << "\" not found";
throw Base::XMLAttributeError(msg.str());
}
}

View File

@@ -3729,7 +3729,7 @@ void GeomLineSegment::Restore (Base::XMLReader &reader)
try {
setPoints(start, end);
}
catch(Base::ValueError &e) {
catch(Base::ValueError&) {
// for a line segment construction, the only possibility of a value error is that
// the points are too close. The best try to restore is incrementing the distance.
// for other objects, the best effort may be just to leave default values.