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

@@ -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());
}
}