Catch more exceptions

This commit is contained in:
Zane U. Ji 2014-06-01 23:28:41 +08:00
parent 0fed15b93b
commit c61ceec6d0
1 changed files with 24 additions and 6 deletions

View File

@ -41,6 +41,7 @@
#include <xercesc/validators/common/ContentSpecNode.hpp> #include <xercesc/validators/common/ContentSpecNode.hpp>
#include <xercesc/validators/schema/SchemaSymbols.hpp> #include <xercesc/validators/schema/SchemaSymbols.hpp>
#include <xercesc/validators/DTD/DTDGrammar.hpp> #include <xercesc/validators/DTD/DTDGrammar.hpp>
#include <xercesc/dom/DOMException.hpp>
using namespace xercesc; using namespace xercesc;
@ -309,14 +310,13 @@ int XMLCALL XmlPromptGenerator::externalentityrefhandler (
parser.setErrorHandler ( &handler ); parser.setErrorHandler ( &handler );
parser.setEntityResolver ( &catalogResolver ); parser.setEntityResolver ( &catalogResolver );
wxString widePublicId = wxString::FromUTF8 ( publicId );
wxString wideSystemId = wxString::FromUTF8 ( systemId );
Grammar *rootGrammar; Grammar *rootGrammar;
try { try {
wxString wideSystemId = wxString::FromUTF8 ( systemId );
std::auto_ptr<InputSource> source ( WrapXerces::resolveEntity std::auto_ptr<InputSource> source ( WrapXerces::resolveEntity
( wxString::FromUTF8 ( publicId ) ( widePublicId , wideSystemId , d->basePath ) );
, wideSystemId
, d->basePath
) );
if ( !source.get() ) if ( !source.get() )
{ {
wxLogError ( _T("Cann't open '%s'"), wideSystemId.c_str() ); wxLogError ( _T("Cann't open '%s'"), wideSystemId.c_str() );
@ -330,11 +330,29 @@ int XMLCALL XmlPromptGenerator::externalentityrefhandler (
if ( !rootGrammar ) if ( !rootGrammar )
return XML_STATUS_ERROR; return XML_STATUS_ERROR;
} }
catch ( SAXParseException& e ) catch ( SAXParseException &e )
{ {
wxLogError ( _T ( "%s" ), handler.getErrors().c_str() ); wxLogError ( _T ( "%s" ), handler.getErrors().c_str() );
return XML_STATUS_ERROR; 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; DTDGrammar* grammar = ( DTDGrammar* ) rootGrammar;
NameIdPoolEnumerator<DTDElementDecl> elemEnum = grammar->getElemEnumerator(); NameIdPoolEnumerator<DTDElementDecl> elemEnum = grammar->getElemEnumerator();