You exit :) Put exit(EXIT_FAILURE) call in your switch statement instead
of returning false, when the case is a fatal error.

I don't wanna interfere with your design decision, but mostly it's
desirable to see all the errors in the document.

Cheers,


-Ozgur Sahoglu


-----Original Message-----
From: Sven Bauhan [mailto:[EMAIL PROTECTED] 
Sent: Friday, February 15, 2008 8:02 AM
To: [email protected]
Subject: returning false in DOMErrorHandler::handleError() does not
abort parsing

Hi,

I wrote an implementation of DOMErrorHandler::handleError(). This
returns 
false on fatal errors like a missing closing tag. But the parsing of the
file 
is not aborted and I did not get an error from parser->parseURI(). What
do I 
have to do, to let the main program abort at fatal errors?

Here is the implementation of DOMErrorHandler:

class XmldbErrorHandler : public DOMErrorHandler {
public:  // --- public methods ---
        //! Default constructor.
        XmldbErrorHandler() {};
        //! Destructor.
        ~XmldbErrorHandler() {};
        //! Reaction on a parser error.
        bool handleError(const DOMError& domError) {
                std::ostringstream errMsg;
    switch ( domError.getSeverity() ) {
                case DOMError::DOM_SEVERITY_WARNING:
        errMsg << "Warning at file ";
        break;
                case DOMError::DOM_SEVERITY_ERROR:
        errMsg << "Error at file ";
        break;
                case DOMError::DOM_SEVERITY_FATAL_ERROR:
                default:
        errMsg << "Fatal Error at file ";
    };
    
    errMsg << XercesString(domError.getLocation()->getURI()).stdStr()
         << ", line " << domError.getLocation()->getLineNumber()
         << ", char " << domError.getLocation()->getColumnNumber()
         << " : " << XercesString(domError.getMessage()).stdStr();

    switch ( domError.getSeverity() ) {
                case DOMError::DOM_SEVERITY_WARNING:
                case DOMError::DOM_SEVERITY_ERROR:
                        d4trace << errMsg.str() << std::endmsg;
                        return true;
                case DOMError::DOM_SEVERITY_FATAL_ERROR:
            d4err << errMsg.str() << std::endmsg;
            return false;
                default:
                        d4err << "XML parser: Unknown severity" <<
std::endmsg;
                        break;
                }
                return false;
        }
private:  // --- private attributes ---
};  // ### class XmldbErrorHandler ###

Thanks, Sven

Reply via email to