Memory context in exception handler - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Memory context in exception handler
Date
Msg-id 200701132319.00246.peter_e@gmx.net
Whole thread Raw
Responses Re: Memory context in exception handler  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
I'm trying to use the PG_TRY/PG_CATCH exception handling:

bool
xml_is_document(xmltype *arg)
{bool        result;xmlDocPtr    doc;
PG_TRY();{    doc = xml_parse((text *) arg, true, true);    result = true;}PG_CATCH();{    ErrorData *errdata =
CopyErrorData();   if (errdata->sqlerrcode == ERRCODE_INVALID_XML_DOCUMENT)    {        FlushErrorState();
result= false;    }    else        PG_RE_THROW();}PG_END_TRY();
 
if (doc)    xmlFreeDoc(doc);
return result;
}

But this fails because CopyErrorData() complains by way of assertion 
that we're still in ErrorContext.  A nearby comment suggests to switch 
away to another context to preserve the data across FlushErrorState(), 
but that doesn't seem necessary in this situation.  Are there other 
reasons why this rule is so rigorously enforced?

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


pgsql-hackers by date:

Previous
From: Christopher Browne
Date:
Subject: Re: [GENERAL] Autovacuum Improvements
Next
From: Jignesh Shah
Date:
Subject: Performance of Parser?