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/

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Reply via email to