[Expat-discuss] Exiting expat handlers
Thu, 17 Oct 2002 09:02:36 -0400
> Hi Warren,
> I see your point here. I just found out that i can use:
> void XMLPARSEAPI XML_UseParserAsHandlerArg(XML_Parser parser); expat API.
> Or simply pass my parser instance as a parameter to the userdata member of callbacks.
> I am using the C library of expat.
> Now, if an error occurs, i can just call XML_FreeParser(myparserinstance); safely
> inside my handler procedure? I am using a C++ wrapper class for the C expat APIs.
No you should not do that, because after returning from the handler there
is still some code being executed in the parser. You need to set a flag
and then free the parser on return from the parse function.
However, since you are using C++, you can throw an exception in the handler,
triggering an immediate return from the parse function, and then - in the exception
handling code - you free the parser.