Subject Re: [firebird-support] Exception handling in loop
Author Thomas Steinmaurer
> Since a block wasn't exited before the exception was handled, wouldn't
> any database statements in the block stand?
> Assume for a moment that it wasn't a constraint violation, but a table
> trigger throwing a custom exception, and the catch block handles it
> instead of handling constraint violations.
>
> FB exception syntax confuses me, as I'm used to other languages where
> the catch is outside the block.

E.g. like in Java? Right.

try {
...
} catch ... {
...
}


The catch (WHEN) block in Firebird PSQL needs to be at the last part of
a BEGIN ... END block.

While you can't do something like that (i = 1 after the exception
handler in the some begin/end block):

declare i integer;
begin
i = 0;
begin
while (i <= 20) do
begin
i = i + 1;
insert into t4(T4_ID) values (:i);
when any do
begin
end
i = 1;
end
end
end


It's fine to continue with something in context of the outer begin/end
block, e.g.:

declare i integer;
begin
i = 0;
begin
while (i <= 20) do
begin
i = i + 1;
insert into t4(T4_ID) values (:i);
when any do
begin
end
end
i = 1;
end
end


Regards
Thomas