You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by "Sharma, Gaurav" <Ga...@Safenet-inc.com> on 2010/07/07 05:03:13 UTC

How to use xerces exceptions

Hi All,

Can anyone tell the exact way of how an exception can be caught if any error occurs while parsing?

   XercesDOMParser* parser = new XercesDOMParser(0, XMLPlatformUtils::fgMemoryManager, gp);
   parser->setDoNamespaces(OEF_TRUE);
   parser->setValidationScheme(XercesDOMParser::Val_Always);
   parser->setDoSchema(OEF_TRUE);
   parser->setValidationSchemaFullChecking(OEF_TRUE);
   parser->setIncludeIgnorableWhitespace(OEF_FALSE);
   parser->setCreateCommentNodes(OEF_FALSE);
   parser->cacheGrammarFromParse(OEF_TRUE);
   parser->useCachedGrammarInParse(OEF_TRUE);
   parser->setLoadSchema(OEF_FALSE);
   parser->setHandleMultipleImports(OEF_TRUE);
   try
   {
     parser->parse(xml_buffer);

   }
   catch(const OutOfMemoryException& e)
   {
      // Exception handling code
   }
   catch(const XMLException& e)
   {
      // Exception handling code
   }
   catch(const DOMException& e)
   {
      // Exception handling code
   }

My code is unable to catch any of the exception generated by parse function in try block while validating against an xsd. So what I do is use getErrorCount() function. But that is not the right way. Exception should be generated and caught in any of the catch block.

Kindly suggest me the right way using xerces exception handling. If possible pls provide some sample lines of code.

With Best Regards
Gaurav Sharma

The information contained in this electronic mail transmission 
may be privileged and confidential, and therefore, protected 
from disclosure. If you have received this communication in 
error, please notify us immediately by replying to this 
message and deleting it from your computer without copying 
or disclosing it.



Re: How to use xerces exceptions

Posted by Vitaly Prapirny <ma...@mebius.net>.
Hi,

Sharma, Gaurav wrote:
> Exception should be generated and caught in any of the catch block.

What particular exception are you expecting in your case?

Some errors are not thrown as exceptions and you should provide error
handler with setErrorHandler method to handle this.

DOMPrint project in samples folder demonstrates this.

Good luck!
	Vitaly

RE: How to use xerces exceptions

Posted by "Sharma, Gaurav" <Ga...@Safenet-inc.com>.
Hi All,

Can any one look into my issue below.
Please help.

With Best Regards
Gaurav Sharma

-----Original Message-----
From: Sharma, Gaurav [mailto:Gaurav.Sharma@Safenet-inc.com] 
Sent: Wednesday, July 07, 2010 8:33 AM
To: c-users@xerces.apache.org
Subject: How to use xerces exceptions

Hi All,

Can anyone tell the exact way of how an exception can be caught if any error occurs while parsing? I am using the code as follows:

   XercesDOMParser* parser = new XercesDOMParser(0, XMLPlatformUtils::fgMemoryManager, gp);
   parser->setDoNamespaces(OEF_TRUE);
   parser->setValidationScheme(XercesDOMParser::Val_Always);
   parser->setDoSchema(OEF_TRUE);
   parser->setValidationSchemaFullChecking(OEF_TRUE);
   parser->setIncludeIgnorableWhitespace(OEF_FALSE);
   parser->setCreateCommentNodes(OEF_FALSE);
   parser->cacheGrammarFromParse(OEF_TRUE);
   parser->useCachedGrammarInParse(OEF_TRUE);
   parser->setLoadSchema(OEF_FALSE);
   parser->setHandleMultipleImports(OEF_TRUE);
   try
   {
     parser->parse(xml_buffer);

   }
   catch(const OutOfMemoryException& e)
   {
      // Exception handling code
   }
   catch(const XMLException& e)
   {
      // Exception handling code
   }
   catch(const DOMException& e)
   {
      // Exception handling code
   }

My code is unable to catch any of the exception generated by parse function in try block while validating against an xsd. So what I do is use getErrorCount() function. But that is not the right way. Exception should be generated and caught in any of the catch block.

Kindly suggest me the right way using xerces exception handling. If possible pls provide some sample lines of code.

With Best Regards
Gaurav Sharma

The information contained in this electronic mail transmission 
may be privileged and confidential, and therefore, protected 
from disclosure. If you have received this communication in 
error, please notify us immediately by replying to this 
message and deleting it from your computer without copying 
or disclosing it.



The information contained in this electronic mail transmission 
may be privileged and confidential, and therefore, protected 
from disclosure. If you have received this communication in 
error, please notify us immediately by replying to this 
message and deleting it from your computer without copying 
or disclosing it.