alternative to PG_CATCH

From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: alternative to PG_CATCH
Date: 2018-12-13 10:33:39
Message-ID: c170919d-c78b-3dac-5ff6-9bd12f7a38bc@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

This is a common pattern:

PG_TRY();
{
... code that might throw ereport(ERROR) ...
}
PG_CATCH();
{
cleanup();
PG_RE_THROW();
}
PG_END_TRY();
cleanup(); /* the same as above */

I've played with a way to express this more compactly:

PG_TRY();
{
... code that might throw ereport(ERROR) ...
}
PG_FINALLY({
cleanup();
});

See attached patch for how this works out in practice.

Thoughts? Other ideas?

One problem is that this currently makes pgindent crash. That's
probably worth fixing anyway. Or perhaps find a way to write this
differently.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachment Content-Type Size
0001-PG_FINALLY.patch text/plain 27.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Sergei Kornilov 2018-12-13 10:51:48 Re: allow online change primary_conninfo
Previous Message Kyotaro HORIGUCHI 2018-12-13 09:42:33 Re: allow online change primary_conninfo