prev_ExecutorRun(queryDesc, direction, count, execute_once);
else
standard_ExecutorRun(queryDesc, direction, count, execute_once);
- nesting_level--;
}
- PG_CATCH();
+ PG_FINALLY();
{
nesting_level--;
- PG_RE_THROW();
}
PG_END_TRY();
}
prev_ExecutorFinish(queryDesc);
else
standard_ExecutorFinish(queryDesc);
- nesting_level--;
}
- PG_CATCH();
+ PG_FINALLY();
{
nesting_level--;
- PG_RE_THROW();
}
PG_END_TRY();
}
}
}
}
- PG_CATCH();
+ PG_FINALLY();
{
/* if needed, close the connection to the database */
if (freeconn)
PQfinish(conn);
- PG_RE_THROW();
}
PG_END_TRY();
- /* if needed, close the connection to the database */
- if (freeconn)
- PQfinish(conn);
-
return (Datum) 0;
}
/* clean up and return the tuplestore */
tuplestore_donestoring(tupstore);
}
-
- PQclear(res);
}
- PG_CATCH();
+ PG_FINALLY();
{
/* be sure to release the libpq result */
PQclear(res);
- PG_RE_THROW();
}
PG_END_TRY();
}
errmsg("statement returning results not allowed")));
}
}
- PG_CATCH();
+ PG_FINALLY();
{
/* if needed, close the connection to the database */
if (freeconn)
PQfinish(conn);
- PG_RE_THROW();
}
PG_END_TRY();
- /* if needed, close the connection to the database */
- if (freeconn)
- PQfinish(conn);
-
PG_RETURN_TEXT_P(sql_cmd_status);
}
pcount = hstoreUniquePairs(pairs, pcount, &buflen);
out = hstorePairs(pairs, pcount, buflen);
}
- PG_CATCH();
+ PG_FINALLY();
{
Py_DECREF(items);
- PG_RE_THROW();
}
PG_END_TRY();
- Py_DECREF(items);
-
PG_RETURN_POINTER(out);
}
out = pushJsonbValue(jsonb_state, WJB_END_OBJECT, NULL);
}
- PG_CATCH();
+ PG_FINALLY();
{
Py_DECREF(items);
- PG_RE_THROW();
}
PG_END_TRY();
- Py_DECREF(items);
-
return out;
}
prev_ExecutorRun(queryDesc, direction, count, execute_once);
else
standard_ExecutorRun(queryDesc, direction, count, execute_once);
- nested_level--;
}
- PG_CATCH();
+ PG_FINALLY();
{
nested_level--;
- PG_RE_THROW();
}
PG_END_TRY();
}
prev_ExecutorFinish(queryDesc);
else
standard_ExecutorFinish(queryDesc);
- nested_level--;
}
- PG_CATCH();
+ PG_FINALLY();
{
nested_level--;
- PG_RE_THROW();
}
PG_END_TRY();
}
standard_ProcessUtility(pstmt, queryString,
context, params, queryEnv,
dest, completionTag);
- nested_level--;
}
- PG_CATCH();
+ PG_FINALLY();
{
nested_level--;
- PG_RE_THROW();
}
PG_END_TRY();
{
trg = createTrgmNFAInternal(®ex, graph, rcontext);
}
- PG_CATCH();
+ PG_FINALLY();
{
pg_regfree(®ex);
- PG_RE_THROW();
}
PG_END_TRY();
- pg_regfree(®ex);
-
/* Clean up all the cruft we created */
MemoryContextSwitchTo(oldcontext);
MemoryContextDelete(tmpcontext);
message_context ? errcontext("%s", message_context) : 0,
sql ? errcontext("remote SQL command: %s", sql) : 0));
}
- PG_CATCH();
+ PG_FINALLY();
{
if (clear)
PQclear(res);
- PG_RE_THROW();
}
PG_END_TRY();
- if (clear)
- PQclear(res);
}
/*
startup_cost, total_cost, rows, width);
if (n != 4)
elog(ERROR, "could not interpret EXPLAIN output: \"%s\"", line);
-
- PQclear(res);
- res = NULL;
}
- PG_CATCH();
+ PG_FINALLY();
{
if (res)
PQclear(res);
- PG_RE_THROW();
}
PG_END_TRY();
}
/* Must be EOF if we didn't get as many tuples as we asked for. */
fsstate->eof_reached = (numrows < fsstate->fetch_size);
-
- PQclear(res);
- res = NULL;
}
- PG_CATCH();
+ PG_FINALLY();
{
if (res)
PQclear(res);
- PG_RE_THROW();
}
PG_END_TRY();
if (PQntuples(res) != 1 || PQnfields(res) != 1)
elog(ERROR, "unexpected result from deparseAnalyzeSizeSql query");
*totalpages = strtoul(PQgetvalue(res, 0, 0), NULL, 10);
-
- PQclear(res);
- res = NULL;
}
- PG_CATCH();
+ PG_FINALLY();
{
if (res)
PQclear(res);
- PG_RE_THROW();
}
PG_END_TRY();
commands = lappend(commands, pstrdup(buf.data));
}
-
- /* Clean up */
- PQclear(res);
- res = NULL;
}
- PG_CATCH();
+ PG_FINALLY();
{
if (res)
PQclear(res);
- PG_RE_THROW();
}
PG_END_TRY();
context, params, queryEnv,
dest, completionTag);
}
- PG_CATCH();
+ PG_FINALLY();
{
sepgsql_context_info = saved_context_info;
- PG_RE_THROW();
}
PG_END_TRY();
- sepgsql_context_info = saved_context_info;
}
/*
{
label = pstrdup(unlabeled);
}
- PG_CATCH();
+ PG_FINALLY();
{
freecon(unlabeled);
- PG_RE_THROW();
}
PG_END_TRY();
-
- freecon(unlabeled);
}
return label;
}
{
result = pstrdup(raw_label);
}
- PG_CATCH();
+ PG_FINALLY();
{
freecon(raw_label);
- PG_RE_THROW();
}
PG_END_TRY();
- freecon(raw_label);
PG_RETURN_TEXT_P(cstring_to_text(result));
}
{
result = pstrdup(qual_label);
}
- PG_CATCH();
+ PG_FINALLY();
{
freecon(qual_label);
- PG_RE_THROW();
}
PG_END_TRY();
- freecon(qual_label);
PG_RETURN_TEXT_P(cstring_to_text(result));
}
SetSecurityLabel(&object, SEPGSQL_LABEL_TAG, context);
}
- PG_CATCH();
+ PG_FINALLY();
{
freecon(context);
- PG_RE_THROW();
}
PG_END_TRY();
- freecon(context);
}
else if (errno == ENOENT)
ereport(WARNING,
exec_object_restorecon(sehnd, AttributeRelationId);
exec_object_restorecon(sehnd, ProcedureRelationId);
}
- PG_CATCH();
+ PG_FINALLY();
{
selabel_close(sehnd);
- PG_RE_THROW();
}
PG_END_TRY();
- selabel_close(sehnd);
-
PG_RETURN_BOOL(true);
}
{
result = pstrdup(ncontext);
}
- PG_CATCH();
+ PG_FINALLY();
{
freecon(ncontext);
- PG_RE_THROW();
}
PG_END_TRY();
- freecon(ncontext);
return result;
}
{
avc_unlabeled = MemoryContextStrdup(avc_mem_cxt, unlabeled);
}
- PG_CATCH();
+ PG_FINALLY();
{
freecon(unlabeled);
- PG_RE_THROW();
}
PG_END_TRY();
-
- freecon(unlabeled);
}
return avc_unlabeled;
}
/* Note: we do not need to re-establish pkey setting */
index_build(heapRelation, iRel, indexInfo, true, true);
}
- PG_CATCH();
+ PG_FINALLY();
{
/* Make sure flag gets cleared on error exit */
ResetReindexProcessing();
- PG_RE_THROW();
}
PG_END_TRY();
- ResetReindexProcessing();
/*
* If the index is marked invalid/not-ready/dead (ie, it's from a failed
i++;
}
}
- PG_CATCH();
+ PG_FINALLY();
{
/* Make sure list gets cleared on error exit */
ResetReindexPending();
- PG_RE_THROW();
}
PG_END_TRY();
- ResetReindexPending();
/*
* Close rel, but continue to hold the lock.
snapshot);
} while (!reachedStop);
}
- PG_CATCH();
+ PG_FINALLY();
{
/* Update shared state */
LWLockAcquire(AsyncQueueLock, LW_SHARED);
QUEUE_BACKEND_POS(MyBackendId) = pos;
LWLockRelease(AsyncQueueLock);
-
- PG_RE_THROW();
}
PG_END_TRY();
- /* Update shared state */
- LWLockAcquire(AsyncQueueLock, LW_SHARED);
- QUEUE_BACKEND_POS(MyBackendId) = pos;
- LWLockRelease(AsyncQueueLock);
-
/* Done with snapshot */
UnregisterSnapshot(snapshot);
}
{
cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W);
}
- PG_CATCH();
+ PG_FINALLY();
{
umask(oumask);
- PG_RE_THROW();
}
PG_END_TRY();
- umask(oumask);
if (cstate->copy_file == NULL)
{
/* copy errno because ereport subfunctions might change it */
{
EventTriggerInvoke(runlist, &trigdata);
}
- PG_CATCH();
+ PG_FINALLY();
{
currentEventTriggerState->in_sql_drop = false;
- PG_RE_THROW();
}
PG_END_TRY();
- currentEventTriggerState->in_sql_drop = false;
/* Cleanup. */
list_free(runlist);
{
EventTriggerInvoke(runlist, &trigdata);
}
- PG_CATCH();
+ PG_FINALLY();
{
currentEventTriggerState->table_rewrite_oid = InvalidOid;
currentEventTriggerState->table_rewrite_reason = 0;
- PG_RE_THROW();
}
PG_END_TRY();
- currentEventTriggerState->table_rewrite_oid = InvalidOid;
- currentEventTriggerState->table_rewrite_reason = 0;
-
/* Cleanup. */
list_free(runlist);
execute_sql_string(c_sql);
}
- PG_CATCH();
+ PG_FINALLY();
{
creating_extension = false;
CurrentExtensionObject = InvalidOid;
- PG_RE_THROW();
}
PG_END_TRY();
- creating_extension = false;
- CurrentExtensionObject = InvalidOid;
-
/*
* Restore the GUC variables we set above.
*/
slotname)));
}
}
- PG_CATCH();
+ PG_FINALLY();
{
- /* Close the connection in case of failure. */
walrcv_disconnect(wrconn);
- PG_RE_THROW();
}
PG_END_TRY();
-
- /* And we are done with the remote side. */
- walrcv_disconnect(wrconn);
}
else
ereport(WARNING,
walrcv_clear_result(res);
}
- PG_CATCH();
+ PG_FINALLY();
{
- /* Close the connection in case of failure */
walrcv_disconnect(wrconn);
- PG_RE_THROW();
}
PG_END_TRY();
- walrcv_disconnect(wrconn);
-
pfree(cmd.data);
table_close(rel, NoLock);
{
result = FunctionCallInvoke(fcinfo);
}
- PG_CATCH();
+ PG_FINALLY();
{
MyTriggerDepth--;
- PG_RE_THROW();
}
PG_END_TRY();
- MyTriggerDepth--;
pgstat_end_function_usage(&fcusage, true);
}
}
}
- PG_CATCH();
+ PG_FINALLY();
{
in_vacuum = false;
VacuumCostActive = false;
- PG_RE_THROW();
}
PG_END_TRY();
- in_vacuum = false;
- VacuumCostActive = false;
-
/*
* Finish up processing.
*/
fd = OpenTransientFilePerm(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
}
- PG_CATCH();
+ PG_FINALLY();
{
umask(oumask);
- PG_RE_THROW();
}
PG_END_TRY();
- umask(oumask);
if (fd < 0)
ereport(ERROR,
(errcode_for_file_access(),
address = ExecRefreshMatView((RefreshMatViewStmt *) parsetree,
queryString, params, completionTag);
}
- PG_CATCH();
+ PG_FINALLY();
{
EventTriggerUndoInhibitCommandCollection();
- PG_RE_THROW();
}
PG_END_TRY();
- EventTriggerUndoInhibitCommandCollection();
break;
case T_CreateTrigStmt:
EventTriggerDDLCommandEnd(parsetree);
}
}
- PG_CATCH();
+ PG_FINALLY();
{
if (needCleanup)
EventTriggerEndCompleteQuery();
- PG_RE_THROW();
}
PG_END_TRY();
-
- if (needCleanup)
- EventTriggerEndCompleteQuery();
}
/*
{
result = pstrdup((char *) str);
}
- PG_CATCH();
+ PG_FINALLY();
{
xmlFree(str);
- PG_RE_THROW();
}
PG_END_TRY();
- xmlFree(str);
}
else
result = NULL;
result = xmlBuffer_to_xmltype(buf);
}
- PG_CATCH();
+ PG_FINALLY()
{
if (nodefree)
nodefree(cur_copy);
if (buf)
xmlBufferFree(buf);
- PG_RE_THROW();
}
PG_END_TRY();
-
- if (nodefree)
- nodefree(cur_copy);
- xmlBufferFree(buf);
}
else
{
result = (xmltype *) cstring_to_text(escaped);
pfree(escaped);
}
- PG_CATCH();
+ PG_FINALLY();
{
xmlFree(str);
- PG_RE_THROW();
}
PG_END_TRY();
- xmlFree(str);
}
return result;
state->typioparams[colnum],
typmod);
}
- PG_CATCH();
+ PG_FINALLY();
{
if (xpathobj != NULL)
xmlXPathFreeObject(xpathobj);
- PG_RE_THROW();
}
PG_END_TRY();
- xmlXPathFreeObject(xpathobj);
-
return result;
#else
NO_XML_SUPPORT();
* (sub)transaction abort. Failure to do so may leave the system in an
* inconsistent state for further processing.
*
+ * For the common case that the error recovery code and the cleanup in the
+ * normal code path are identical, the following can be used instead:
+ *
+ * PG_TRY();
+ * {
+ * ... code that might throw ereport(ERROR) ...
+ * }
+ * PG_FINALLY();
+ * {
+ * ... cleanup code ...
+ * }
+ * PG_END_TRY();
+ *
+ * The cleanup code will be run in either case, and any error will be rethrown
+ * afterwards.
+ *
+ * You cannot use both PG_CATCH() and PG_FINALLY() in the same
+ * PG_TRY()/PG_END_TRY() block.
+ *
* Note: while the system will correctly propagate any new ereport(ERROR)
* occurring in the recovery section, there is a small limit on the number
* of levels this will work for. It's best to keep the error recovery
*/
#define PG_TRY() \
do { \
- sigjmp_buf *save_exception_stack = PG_exception_stack; \
- ErrorContextCallback *save_context_stack = error_context_stack; \
- sigjmp_buf local_sigjmp_buf; \
- if (sigsetjmp(local_sigjmp_buf, 0) == 0) \
+ sigjmp_buf *_save_exception_stack = PG_exception_stack; \
+ ErrorContextCallback *_save_context_stack = error_context_stack; \
+ sigjmp_buf _local_sigjmp_buf; \
+ bool _do_rethrow = false; \
+ if (sigsetjmp(_local_sigjmp_buf, 0) == 0) \
{ \
- PG_exception_stack = &local_sigjmp_buf
+ PG_exception_stack = &_local_sigjmp_buf
#define PG_CATCH() \
} \
else \
{ \
- PG_exception_stack = save_exception_stack; \
- error_context_stack = save_context_stack
+ PG_exception_stack = _save_exception_stack; \
+ error_context_stack = _save_context_stack
+
+#define PG_FINALLY() \
+ } \
+ else \
+ _do_rethrow = true; \
+ {
#define PG_END_TRY() \
} \
- PG_exception_stack = save_exception_stack; \
- error_context_stack = save_context_stack; \
+ PG_exception_stack = _save_exception_stack; \
+ error_context_stack = _save_context_stack; \
+ if (_do_rethrow) \
+ PG_RE_THROW(); \
} while (0)
/*
else
retval = plperl_func_handler(fcinfo);
}
- PG_CATCH();
+ PG_FINALLY();
{
current_call_data = save_call_data;
activate_interpreter(oldinterp);
if (this_call_data.prodesc)
decrement_prodesc_refcount(this_call_data.prodesc);
- PG_RE_THROW();
}
PG_END_TRY();
- current_call_data = save_call_data;
- activate_interpreter(oldinterp);
- if (this_call_data.prodesc)
- decrement_prodesc_refcount(this_call_data.prodesc);
return retval;
}
if (SPI_finish() != SPI_OK_FINISH)
elog(ERROR, "SPI_finish() failed");
}
- PG_CATCH();
+ PG_FINALLY();
{
if (desc.reference)
SvREFCNT_dec_current(desc.reference);
current_call_data = save_call_data;
activate_interpreter(oldinterp);
- PG_RE_THROW();
}
PG_END_TRY();
- if (desc.reference)
- SvREFCNT_dec_current(desc.reference);
-
- current_call_data = save_call_data;
- activate_interpreter(oldinterp);
-
error_context_stack = pl_error_context.previous;
PG_RETURN_VOID();
else
retval = plpgsql_exec_function(func, fcinfo, NULL, !nonatomic);
}
- PG_CATCH();
+ PG_FINALLY();
{
- /* Decrement use-count, restore cur_estate, and propagate error */
+ /* Decrement use-count, restore cur_estate */
func->use_count--;
func->cur_estate = save_cur_estate;
- PG_RE_THROW();
}
PG_END_TRY();
- func->use_count--;
-
- func->cur_estate = save_cur_estate;
-
/*
* Disconnect from SPI manager
*/
plan->values[j] = PLy_output_convert(arg, elem, &isnull);
nulls[j] = isnull ? 'n' : ' ';
}
- PG_CATCH();
+ PG_FINALLY();
{
Py_DECREF(elem);
- PG_RE_THROW();
}
PG_END_TRY();
- Py_DECREF(elem);
}
portal = SPI_cursor_open(NULL, plan->plan, plan->values, nulls,
(constraint_name) ? err_generic_string(PG_DIAG_CONSTRAINT_NAME,
constraint_name) : 0));
}
- PG_CATCH();
+ PG_FINALLY();
{
if (fmt)
pfree(emsg.data);
pfree(tbmsg);
Py_XDECREF(exc);
Py_XDECREF(val);
-
- PG_RE_THROW();
}
PG_END_TRY();
-
- if (fmt)
- pfree(emsg.data);
- if (xmsg)
- pfree(xmsg);
- if (tbmsg)
- pfree(tbmsg);
- Py_XDECREF(exc);
- Py_XDECREF(val);
}
/*
}
}
}
- PG_CATCH();
+ PG_FINALLY();
{
Py_XDECREF(plargs);
Py_XDECREF(plrv);
-
- PG_RE_THROW();
}
PG_END_TRY();
- Py_DECREF(plargs);
- Py_DECREF(plrv);
-
return rv;
}
*/
Assert(list_length(explicit_subtransactions) >= save_subxact_level);
}
- PG_CATCH();
+ PG_FINALLY();
{
PLy_abort_open_subtransactions(save_subxact_level);
- PG_RE_THROW();
}
PG_END_TRY();
- PLy_abort_open_subtransactions(save_subxact_level);
-
/* If the Python code returned an error, propagate it */
if (rv == NULL)
PLy_elog(ERROR, NULL);
plan->values[j] = PLy_output_convert(arg, elem, &isnull);
nulls[j] = isnull ? 'n' : ' ';
}
- PG_CATCH();
+ PG_FINALLY();
{
Py_DECREF(elem);
- PG_RE_THROW();
}
PG_END_TRY();
- Py_DECREF(elem);
}
rv = SPI_execute_plan(plan->plan, plan->values, nulls,
memcpy(VARDATA(result), plrv_sc, len);
rv = PointerGetDatum(result);
}
- PG_CATCH();
+ PG_FINALLY();
{
Py_XDECREF(plrv_so);
- PG_RE_THROW();
}
PG_END_TRY();
- Py_XDECREF(plrv_so);
-
return rv;
}
retval = pltcl_func_handler(fcinfo, ¤t_call_state, pltrusted);
}
}
- PG_CATCH();
+ PG_FINALLY();
{
/* Restore static pointer, then clean up the prodesc refcount if any */
+ /* (We're being paranoid in case an error is thrown in context deletion) */
pltcl_current_call_state = save_call_state;
if (current_call_state.prodesc != NULL)
{
if (--current_call_state.prodesc->fn_refcount == 0)
MemoryContextDelete(current_call_state.prodesc->fn_cxt);
}
- PG_RE_THROW();
}
PG_END_TRY();
- /* Restore static pointer, then clean up the prodesc refcount if any */
- /* (We're being paranoid in case an error is thrown in context deletion) */
- pltcl_current_call_state = save_call_state;
- if (current_call_state.prodesc != NULL)
- {
- Assert(current_call_state.prodesc->fn_refcount > 0);
- if (--current_call_state.prodesc->fn_refcount == 0)
- MemoryContextDelete(current_call_state.prodesc->fn_cxt);
- }
-
return retval;
}