Issue Details (XML | Word | Printable)

Key: CORE-1953
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Dmitry Yemanov
Reporter: prenosil
Votes: 3
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
Firebird Core

Broken EXCEPTION handling.

Created: 23/Jun/08 09:43 AM   Updated: 05/Mar/09 10:11 AM
Component/s: Engine
Affects Version/s: 1.0.3, 2.0.0, 1.5.4, 2.0.1, 2.0.2, 2.0.3, 1.5.5, 2.1.0, 2.0.4, 2.1.1
Fix Version/s: None

Environment: WinXP
Issue Links:
Relate
 


 Description  « Hide
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.


 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Dmitry Yemanov added a comment - 23/Jun/08 10:34 AM
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.

Smirnoff Serg added a comment - 24/Jun/08 04:59 AM
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;

Cosmin Apreutesei added a comment - 05/Mar/09 09:48 AM
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" :)

Cosmin Apreutesei added a comment - 05/Mar/09 10:11 AM