Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken EXCEPTION handling. [CORE1953] #2391

Open
firebird-automations opened this issue Jun 23, 2008 · 8 comments
Open

Broken EXCEPTION handling. [CORE1953] #2391

firebird-automations opened this issue Jun 23, 2008 · 8 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: prenosil (prenosil)

Relate to CORE1956

Votes: 3

User defined EXCEPTION caught by WHEN handler does not undo previous actions.
Example script:

CREATE EXCEPTION EX 'Test';
CREATE TABLE TEST(A INTEGER);
INSERT INTO TEST(A) VALUES(1000);
COMMIT;

SELECT * FROM TEST;
A

   1000

EXECUTE BLOCK AS
BEGIN
UPDATE TEST SET A=A+10;
EXCEPTION EX;
END;

Error: Test

SELECT * FROM TEST;
A

   1000    \.\.\. o\.k\., the Update was undone

EXECUTE BLOCK AS
BEGIN
UPDATE TEST SET A=A+10;
EXCEPTION EX;
WHEN ANY DO BEGIN END
END;

SELECT * FROM TEST;
A

   1010   \.\.\. wrong \!\!\!\!\!

EXECUTE BLOCK AS
BEGIN
UPDATE TEST SET A=A+10;
EXCEPTION EX;
WHEN EXCEPTION EX DO BEGIN END
END;

SELECT * FROM TEST;
A

   1020   \.\.\. wrong \!\!\!\!\!

EXECUTE BLOCK AS
DECLARE VARIABLE I INTEGER;
BEGIN
UPDATE TEST SET A=A+10;
I = 1 / 0;
WHEN ANY DO BEGIN END
END;

SELECT * FROM TEST;
A

   1020   \.\.\. other kinds of exceptions work o\.k\.
@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

Believe or not, this is done intentionally, but don't ask me about the reasons :-) This is how the engine works since the very beginning.

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

Link: This issue relate to CORE1956 [ CORE1956 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: Smirnoff Serg (wildsery)

As I understand mechanics of exceptions, you allways should do like this (additional begin..end):

EXECUTE BLOCK AS
BEGIN
BEGIN
UPDATE TEST SET A=A+10;
EXCEPTION EX;
END
WHEN EXCEPTION EX DO BEGIN END
END;

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

priority: Critical [ 2 ] => Major [ 3 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

assignee: Dmitry Yemanov [ dimitr ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

Version: 2.0.4 [ 10211 ]

Version: 1.5.5 [ 10220 ]

Version: 2.0.3 [ 10200 ]

Version: 2.0.2 [ 10130 ]

Version: 2.0.1 [ 10090 ]

Version: 1.5.4 [ 10100 ]

Version: 2.0.0 [ 10091 ]

Version: 1.0.3 [ 10006 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: Cosmin Apreutesei (cosmin_ap2)

quite annoying remembering this all the time... you'll argue that changing this behavior could break existing users code, but you could also consider the amount of code it will "fix" :)

@firebird-automations
Copy link
Collaborator Author

Commented by: Cosmin Apreutesei (cosmin_ap2)

more info (still completely relevant?): http://ibdeveloper.com/issues/issue-1-sep-1-2005/inside-savepoints/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment