arabica/include/SAX/helpers/CatchErrorHandler.hpp

57 lines
1.3 KiB
C++
Raw Normal View History

#ifndef ARABICA_CATCH_ERROR_HANDLER_H
#define ARABICA_CATCH_ERROR_HANDLER_H
2007-09-05 00:55:47 +02:00
#include <SAX/ErrorHandler.hpp>
/**
* An ErrorHandler implementation that keeps hold of any errors for later reporting.
*/
namespace SAX
{
template<class string_type>
class CatchErrorHandler : public SAX::basic_ErrorHandler<string_type>
{
public:
typedef SAX::basic_SAXParseException<string_type> SAXParseExceptionT;
CatchErrorHandler() : errors_() { }
virtual ~CatchErrorHandler() { }
virtual void warning(const SAXParseExceptionT& exception)
{
hold(exception);
} // warning
virtual void error(const SAXParseExceptionT& exception)
{
hold(exception);
} // error
virtual void fatalError(const SAXParseExceptionT& exception)
{
hold(exception);
} // fatalError
bool errorsReported() const { return !errors_.empty(); }
const std::string& errors() const { return errors_; }
2003-10-29 17:20:07 +01:00
void reset() { errors_.erase(); }
private:
void hold(const SAXParseExceptionT& exception)
{
2004-02-24 17:07:09 +01:00
// if I just call exception.what() VS.NET seems to ignore the
// dynamic dispatch, and inlines std::exception::what to give "Unknown Exception".
// Naughty!
// doing this prevents it doing that
// GCC got it right
errors_ += SAXParseExceptionT(exception).what();
} // hold
std::string errors_;
}; // class CatchErrorHandler
} // namespace Arabica
2004-01-27 00:20:08 +01:00
#endif