Subject RE: [firebird-support] Exception handling in loop
Author Rick Debay
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.

-----Original Message-----
From: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com] On Behalf Of Thomas
Steinmaurer
Sent: Thursday, January 10, 2013 1:51 PM
To: firebird-support@yahoogroups.com
Subject: Re: [firebird-support] Exception handling in loop

> I want to select a bunch of items and insert them somewhere else. If
> the insert fails because of a duplicate primary key or unique
> constraint, I want to abandon that particular item and continue with
> the rest.
> This code outlines my logic. Is this correct for what I'm trying to
> accomplish?
>
> BEGIN
>
> FOR SELECT DO BEGIN
>
> BEGIN
>
> INSERT
>
> END /* INSERT */
>
> WHEN GDSCODE unique_key_violation DO
> BEGIN
> /* NOP */
> END
>
> END /* SELECT */
>
> END /* PROCEDURE */

I guess this should be:

BEGIN
FOR SELECT DO
BEGIN
INSERT
WHEN GDSCODE unique_key_violation DO
BEGIN
/* NOP */
END
END /* SELECT */
END /* PROCEDURE */



Regards,
Thomas












------------------------------------

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

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