From c61ceec6d0cad362679b283ce4e94b1c9d1f2864 Mon Sep 17 00:00:00 2001 From: "Zane U. Ji" Date: Sun, 1 Jun 2014 23:28:41 +0800 Subject: [PATCH] Catch more exceptions --- src/xmlpromptgenerator.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/xmlpromptgenerator.cpp b/src/xmlpromptgenerator.cpp index 25178ad..79f08fd 100644 --- a/src/xmlpromptgenerator.cpp +++ b/src/xmlpromptgenerator.cpp @@ -41,6 +41,7 @@ #include #include #include +#include using namespace xercesc; @@ -309,14 +310,13 @@ int XMLCALL XmlPromptGenerator::externalentityrefhandler ( parser.setErrorHandler ( &handler ); parser.setEntityResolver ( &catalogResolver ); + wxString widePublicId = wxString::FromUTF8 ( publicId ); + wxString wideSystemId = wxString::FromUTF8 ( systemId ); + Grammar *rootGrammar; try { - wxString wideSystemId = wxString::FromUTF8 ( systemId ); std::auto_ptr source ( WrapXerces::resolveEntity - ( wxString::FromUTF8 ( publicId ) - , wideSystemId - , d->basePath - ) ); + ( widePublicId , wideSystemId , d->basePath ) ); if ( !source.get() ) { wxLogError ( _T("Cann't open '%s'"), wideSystemId.c_str() ); @@ -330,11 +330,29 @@ int XMLCALL XmlPromptGenerator::externalentityrefhandler ( if ( !rootGrammar ) return XML_STATUS_ERROR; } - catch ( SAXParseException& e ) + catch ( SAXParseException &e ) { wxLogError ( _T ( "%s" ), handler.getErrors().c_str() ); return XML_STATUS_ERROR; } + catch ( XMLException &e ) + { + wxString error = WrapXerces::toString ( e.getMessage() ); + wxLogError ( _T ( "%s" ), error.c_str() ); + return XML_STATUS_ERROR; + } + catch ( DOMException &e ) + { + wxString error = WrapXerces::toString ( e.getMessage() ); + wxLogError ( _T ( "%s" ), error.c_str() ); + return XML_STATUS_ERROR; + } + catch (...) + { + wxLogError ( _T ( "Failed to load: %s %s"), widePublicId.c_str() + , wideSystemId.c_str() ); + return XML_STATUS_ERROR; + } DTDGrammar* grammar = ( DTDGrammar* ) rootGrammar; NameIdPoolEnumerator elemEnum = grammar->getElemEnumerator();