|Subject||RE: [firebird-support] Transactions & exception trapping|
> The handler is not embedded in the loop that it handles: it followsdirectly after
What I originally posted is exactly what our code looks like. The WHEN
handler is the last statement INSIDE the loop.
If an insert statement throws an exception, we see the loop continue and
the exception logged.
The issue is that it appears that sometimes the insert succeeds and the
update fails and the loop continues.
[mailto:email@example.com] On Behalf Of Helen Borrie
Sent: Friday, August 10, 2012 4:25 PM
Subject: RE: [firebird-support] Transactions & exception trapping
At 05:00 AM 11/08/2012, Rick Debay wrote:
>FOR ... BEGINThe handler is not embedded in the loop that it handles: it follows
> INSERT_PROCEDURE RETURNING VALUE
> UPDATE TABLE WITH VALUE
> WHEN ... BEGIN
>If the insert procedure directly or indirectly causes an exception the
>insert will be abandoned, the update will be skipped, and all data from
>previous or subsequent non-erroneous loop iterations will be preserved.
>Now if the update fails, would the inserted data within the same loop
>iteration be preserved? I've been assuming that everything within the
>BEGIN...END was abandoned.
directly after. The flow should be:
FOR ... do
INSERT_PROCEDURE RETURNING VALUE
UPDATE TABLE WITH VALUE
WHEN ... do
If an exception occurs anywhere in an iteration of that loop, everything
within that iteration is abandoned, control drops into the WHEN block
and executes that before returning to the top of the loop.
If a handler block is not found directly after the looping block,
control moves out through the layers until one is found that fits the
exception. Everything enclosed by the block whose handler is found is
Ultimately, if no explicit handler is found in the enclosing layers that
fits the exception, control drops to the EXIT statement and the entire
work of the procedure is abandoned.
Visit http://www.firebirdsql.org and click the Resources item on the
main (top) menu. Try Knowledgebase and FAQ links !
Also search the knowledgebases at http://www.ibphoenix.com
Yahoo! Groups Links