11.7(win): Traditional error handling: ON ERROR and error in

Posted by Stefan Marquardt on 17-Jan-2020 10:34

Hello,

triggers works fine but I wanted to test what happens in case of errors.

I defined a .p as a write trigger of a table (without CRC)

Within this trigger i added two lines

TRIGGER PROCEDURE FOR WRITE OF...
APPLY "Error".

My little test in the procedure editor:

FIND FIRST ... EXCLUSIVE-LOCK.
DISPLAY ...  // Display a field

DO ON ERROR UNDO, RETRY ON STOP UNDO, RETRY ON QUIT UNDO, RETRY:
 IF RETRY THEN
  DO:
   MESSAGE "error" VIEW-AS ALERT-BOX INFORMATION BUTTONS OK.
   RETURN.
END.

... = "A".   // Update a field

 //VALIDATE ...

MESSAGE "All fine".


END.

The trigger undo the transaction (no update occurs, field doesn't get A) but ON ERROR doesn't react and "All Fine" is displayed.
Validate fires the trigger directly and ON ERROR works

What is the trick, that the code will be notified about the UNDO with the old On ERROR style?

Posted by Fernando Souza on 17-Jan-2020 13:26

Yes, you will need to return error or use structure error handling in the trigger code.

But then in the code that you update the record, note that the record is not written out until the end of its scope, or when when you do something to force validation or release of the record, such as VALIDATE/RELEASE. So in your example, the record will get out of scope at the end of the procedure, outside the DO ON block you have coded.

All Replies

Posted by Lieven De Foor on 17-Jan-2020 11:00

Try RETURN ERROR or UNDO, THROW NEW AppError().

Posted by Stefan Marquardt on 17-Jan-2020 11:09

RETURN ERROR has the same effect, UNDO in secret.

With UNDO, THROW NEW Progress.Lang.AppError("Error",1) the same effect plus getting the Error message AFTER "all fine".

Posted by Lieven De Foor on 17-Jan-2020 11:31

When I try this I don't get the "All fine" message.

My example:

ON WRITE OF Customer OVERRIDE DO:
    RETURN ERROR.
END.

FIND FIRST Customer EXCLUSIVE-LOCK.

DO ON ERROR UNDO, RETRY:

    IF RETRY
    THEN DO:
        MESSAGE "Something went wrong..."
            VIEW-AS ALERT-BOX.
        RETURN.
    END.

    ASSIGN Customer.Phone = "test".

    VALIDATE Customer.

    MESSAGE "All fine..."
        VIEW-AS ALERT-BOX.

END.

Posted by Stefan Marquardt on 17-Jan-2020 12:02

I wrote with VALIDATE it works but without it doesn't, the update doesn't occur and ON ERROR seems not to work

Posted by Fernando Souza on 17-Jan-2020 13:26

Yes, you will need to return error or use structure error handling in the trigger code.

But then in the code that you update the record, note that the record is not written out until the end of its scope, or when when you do something to force validation or release of the record, such as VALIDATE/RELEASE. So in your example, the record will get out of scope at the end of the procedure, outside the DO ON block you have coded.

Posted by Stefan Marquardt on 17-Jan-2020 13:44

Fernando, i just identified the same. The trigger is fired after the DO block caused by the FIND.

So, it's normal and my bad, working with headache isn't the best :-)

This thread is closed