I have registered three handlers with expat parser: - start -end - text
And from the main program, I read the xml file, buffer it and invoke XML_Parse API. Something like this:
try {
if( ! XML_Parse (....))
{
// throw user-defined expection here
}
catch(...)
{
}
} // end of try
catch(...)
{
}
If XML_Parse returns 0 on failure, an exception is being thrown from inside if. And it is caught in inner catch block.
Here is my question: If the user-defined exception is thrown from any of the handlers during parsing, will that be caught in the outer catch ?
If yes, its actually not happening in my code. Instead, it is dumping core and stack shows that throw is leading to std:terminate. Do I have to perform anything else before throwing exceptions from HANDLERS.
Thanks.
If you throw an exception from within a
try{/*stuff*/}
block and thethrow
was deeply nested, the stack will unwind all the way to the matching outercatch(...)
function. If your handlers had assigned heap memory, you will need to deal with that either by usingshared_ptr<>
or deleting explicitly and carefully. If your handlers were inside thetry
block, then the exception should behave as normal.