Re: Nicely exiting PG_TRY and PG_CATCH
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mikhail Gribkov <youzhick@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Date: 2022-10-07T21:19:03Z
Lists: pgsql-hackers
Mikhail Gribkov <youzhick@gmail.com> writes: > Usually it's not a good idea to exit PG_TRY() block via return statement. > Otherwise it would leave PG_exception_stack global variable in a wrong > state and next ereport() will jump to some junk address. Yeah, you can't return or goto out of the PG_TRY part. > Another suspicious case is PG_CATCH block in jsonb_plpython.c: This should be OK. The PG_CATCH and PG_FINALLY macros are set up so that we've fully restored that state *before* we execute any of the error-handling code. It would be basically impossible to have a guarantee that CATCH blocks never throw errors; they'd be so restricted as to be near useless, like signal handlers. regards, tom lane
Commits
-
Move return statements out of PG_TRY blocks.
- 0af386b0f4b8 11.20 landed
- 24964394a972 12.15 landed
- 800531846ef7 13.11 landed
- 52c9cf3239b8 14.8 landed
- 825ebc9848fd 15.3 landed
- 57d0051706b8 16.0 landed
-
Add -Wshadow=compatible-local to the standard compilation flags
- 0fe954c28584 16.0 cited