Kbase P176872: Duplicate record errors from block not caught in CATCH statement
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  11/22/2010 |
|
Status: Unverified
SYMPTOM(s):
Duplicate record errors from block not caught in CATCH statement
CATCH block doesn't catch some errors in block where errors originate
** <file-name> already exists with <field/value...>. (132)
Example code to reproduce the issue:
DEFINE TEMP-TABLE ttCust
FIELD CustNum AS INTEGER INITIAL 1
FIELD NAME AS CHARACTER
INDEX CustNum IS PRIMARY UNIQUE CustNum.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DO i = 1 TO 2 ON ERROR UNDO, NEXT:
CREATE ttCust.
ASSIGN CustNum = 1
NAME = STRING(i).
CATCH oError AS Progress.Lang.Error:
MESSAGE oError:GetMessage(1)
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END CATCH.
END.
FACT(s) (Environment):
All Supported Operating Systems
OpenEdge 10.x
CAUSE:
This is expected behavior. When the index manager sees the INITIAL value of the index field has not changed it postpones the WRITE of the record until the end of the transaction, which is in this case the end of the procedure scope because the block defines a weak scope. By the time the index manager attempts to write the record in this case the CATCH block has already expired.
FIX:
There are a couple ways to handle this properly, enumerated below:
1) Use the RELEASE statement to force the index manager to write the record before the end of the block.
2) Add the TRANSACTION keyword to the block, thus increasing the strength of the block scope and containing the error.
In either case you should also do one of the following to ensure that the erroneous index entry is corrected or cleaned up:
a) Add code to the CATCH block to correct the erroneous index entry in the record which was created
b) Delete the record in the CATCH block to ensure that the index manager doesn't attempt to write an erroneous index entry again
c) Use an UNDOable temp-table, which will have the effect of deleting the erroneous buffer when the error condition is raised