some thoughts concerning the new errorhandling in 10.1C

Posted by agent_008_nl on 01-Jul-2008 05:13

Playing for the first time with it. The new ways seem a good addition
to the old ways, but keep giving me itches. First question: why do I
have to include 'ROUTINE-LEVEL ON ERROR UNDO, THROW.' in every .p or
.cls? Wouldn't a session-setting be handy addition? And would it be an
idea to change default block properties to ON ERROR UNDO, THROW with
maybe the same setting? Because we programmers make mistakes I keep
finding an extra error-catch mechanism like below (the extras are
commented out) necessary. Try this democode with the extras commented
out and uncommented to see what happens. Any thoughts?
Small bonus: remove PROCEDURE someProcJustMaintainedByADummy and run
the code. And now change the call to RUN
someProcJustMaintainedByADummy IN THIS PROCEDURE while PROCEDURE
someProcJustMaintainedByADummy keeps removed. (first the STOP
condition is raised, later the ERROR, wouldn't the last be preferrable
in both cases?).

Regards,

Stefan.


ROUTINE-LEVEL ON ERROR UNDO, THROW.

DEFINE TEMP-TABLE ttABC
FIELD anInt AS INTEGER.

DEF VAR iStat AS INT NO-UNDO.

RUN a (OUTPUT iStat).

FIND FIRST ttABC NO-ERROR.
MESSAGE ' status ' iStat IF AVAIL ttABC THEN ' ttABC found, a corrupt
record still exists with ttABC.anInt ' + STRING(ttABC.anInt) ELSE '
ttABC not found' VIEW-AS ALERT-BOX.

PROCEDURE a:
DEFINE OUTPUT PARAMETER poiStatus AS INTEGER NO-UNDO.

/* IF NOT TRANSACTION THEN _msg = 0. */

TransBlock:
DO TRANSACTION ON ERROR UNDO TransBlock, RETRY TransBlock:

IF RETRY THEN
DO:
IF poiStatus = 0 THEN poiStatus = 99.
RETURN.
END.

CREATE ttABC.

RUN someProcJustMaintainedByADummy.


/* IF _msg(1) NE 0 THEN UNDO TransBlock, THROW NEW
Progress.Lang.AppError("Catch the otherwise uncatched", 99). */

CATCH eProError AS Progress.Lang.ProError:
poiStatus = 99.
MESSAGE eProError:getMessage(1) VIEW-AS ALERT-BOX.
DELETE OBJECT eProError.
END CATCH.

END. /* TransBlock */
END PROCEDURE.

PROCEDURE someProcJustMaintainedByADummy:
DEF VAR intVar AS i NO-UNDO.

FOR FIRST ttABC: /* the dummy forgot to add ON ERROR UNDO, THROW */
RUN s IN THIS-PROCEDURE (OUTPUT intVar).
ttABC.anInt = intVar.
END.
END PROCEDURE.

PROCEDURE s:
END PROCEDURE.

All Replies

This thread is closed