You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by bibble_235 <iw...@bibble.co.nz> on 2011/02/24 07:39:48 UTC

Error Handling

Hi

Having trouble with the error handling of xerces. Using the code below I am
unable to detect that the Error (which is neither the Schema or the Xml are
found). I have done some tracing and found that the SAXParseException does
not receive the full details of the error.

It looks like 

IGXMLScanner fails in scanDocument and calls emitError
emitError has 
toEmit = XMLException_fatal
originalExceptCode = Scan_CouldNotOpenSource
text1 = Could not load message

This is never propagated to the SAXParseException

This following line exists on 917 of the source file.

        if (!gMsgLoader->loadMsg(toEmit, errText, maxChars, text1, text2,
text3, text4, fMemoryManager))
        {
                // <TBD> Should probably load a default message here
        }

Can someone help please? I can of course with the exception by putting the
file in the correct location but surely you should be able to catch this
error.
 
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/sax2/DefaultHandler.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <iostream>
 
XERCES_CPP_NAMESPACE_USE

class mdsXercesErrorHandler : public DefaultHandler
{
public:
	void warning(const SAXParseException& inParseException)
{showError(inParseException);};
    void error(const SAXParseException& inParseException)
{showError(inParseException);};
    void fatalError(const SAXParseException& inParseException)
{showError(inParseException);};
    void showError(const SAXParseException& inParseException);
private:
};
 
void
mdsXercesErrorHandler::showError(const SAXParseException& inParseException)
{
    char* myErrorAsChar =
xercesc::XMLString::transcode(inParseException.getMessage());
    std::cout << "Warning:" << myErrorAsChar << ". Thanks" << std::endl;
    XMLString::release(&myErrorAsChar);
};
 
int
main(int argc, char* argv[])
{
    try
    {
        xercesc::XMLPlatformUtils::Initialize();
 
        XercesDOMParser* m_ConfigFileParser = new XercesDOMParser;
        mdsXercesErrorHandler* myErrorHandler = new mdsXercesErrorHandler();
 
       
m_ConfigFileParser->setValidationScheme(xercesc::XercesDOMParser::Val_Always);
        m_ConfigFileParser->setDoNamespaces(true);
        m_ConfigFileParser->setDoSchema(true);
        m_ConfigFileParser->setLoadExternalDTD(false);
        m_ConfigFileParser->setValidationSchemaFullChecking(true);
        m_ConfigFileParser->setValidationConstraintFatal(true);
        m_ConfigFileParser->setIncludeIgnorableWhitespace(false);
        m_ConfigFileParser->setErrorHandler(myErrorHandler);
 
       
m_ConfigFileParser->setExternalNoNamespaceSchemaLocation("Schema.xsd");
        m_ConfigFileParser->parse("File.xml");
       
        delete myErrorHandler;
        delete m_ConfigFileParser;
    }
    catch(xercesc::XMLException& myException)
    {
        std::cout << "Got an Error" << std::endl;
    }
}

-- 
View this message in context: http://old.nabble.com/Error-Handling-tp31001284p31001284.html
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org