FINALLY statement

Defines a final end block for any ABL block. An end block is an ABL block that can occur only within another block. The block containing the end block is known as the associated block. End blocks must occur between the last line of executable code in the associated block and its END statement.

For any ABL block statement, the FINALLY statement defines an optional end block that contains ABL code to execute at the conclusion of all other processing in the associated block or once at the conclusion of each iteration of an associated iterating block. This is the syntax for the FINALLY statement and its related blocks:

Syntax

block-statements 

    FINALLY :

        finally-logic 

    END [ FINALLY ] .

[ block-end-statement ]
block-statements
All of the statements of an enclosing associated ABL block, including an external procedure block, except for its block-end-statement. The enclosing associated block can be any ABL block, including another FINALLY block
finally-logic
All statements allowed in a FINALLY block, which can include any valid ABL statement. For more information on FINALLY block execution, see the Notes for this reference entry.
block-end-statement
For all associated ABL blocks except a main external procedure block, the END statement terminating the enclosing associated block of the FINALLY block. External procedure blocks have no terminating END statement.

Examples

As shown in r-finally01.p, the FINALLY block executes before any flow-of-control (LEAVE, NEXT, RETRY, RETURN, or THROW) options are executed for the associated block. For iterating blocks, the FINALLY block executes after each iteration of the block.

r-finally01.p

DO ON ERROR UNDO, LEAVE:
  /* Since Customer 1000 does not exist, the FIND statement raises ERROR and
     execution goes to the FINALLY block before the LEAVE option executes. */
  FIND Customer 1000.
  MESSAGE "This message never appears because of ERROR condition."
    VIEW-AS ALERT-BOX BUTTONS OK.

  FINALLY:
    MESSAGE "Inside FINALLY block." VIEW-AS ALERT-BOX BUTTONS OK.
    /* LEAVE DO block here */
  END FINALLY.
END. /* DO */

MESSAGE "Out of DO block." VIEW-AS ALERT-BOX BUTTONS OK.

In r-finally02.p, after ERROR is raised, execution goes to the CATCH block and then to the FINALLY block.

r-finally02.p

DO ON ERROR UNDO, LEAVE:
  /* Since Customer 1000 does not exist, the FIND statement raises ERROR and
     execution goes to CATCH block. */
  FIND Customer 1000.
  MESSAGE "This message never appears because of ERROR condition." 
    VIEW-AS ALERT-BOX BUTTONS OK.

  CATCH eSysError AS Progress.Lang.SysError:
    /* Handler code for SysError condition */
    MESSAGE "Inside CATCH block." VIEW-AS ALERT-BOX BUTTONS OK.
    /* Execution goes to FINALLY before leaving DO block. */
  END CATCH.

  FINALLY:
    /* Your code */
    MESSAGE "Inside FINALLY block." VIEW-AS ALERT-BOX BUTTONS OK.
    /* LEAVE DO block here. */
  END FINALLY.
END. /* DO */

MESSAGE "Out of DO block." VIEW-AS ALERT-BOX BUTTONS OK.

In r-finally03.p, after ERROR is raised, execution goes to the CATCH block, which re-throws the error. However, the FINALLY block executes before the error goes to the CATCH block associated with the procedure block.

r-finally03.p

DO ON ERROR UNDO, LEAVE:
  /* Since Customer 1000 does not exist, the FIND statement raises ERROR and
     execution goes to CATCH block. */
  FIND Customer 1000.
  MESSAGE "This message never appears because of ERROR condition." 
    VIEW-AS ALERT-BOX BUTTONS OK.

  CATCH eSysError AS Progress.Lang.SysError:
    /* Handler code for SysError condition */
    MESSAGE "Inside CATCH block." VIEW-AS ALERT-BOX BUTTONS OK.
    /* Execution goes to FINALLY before leaving DO block. */
    UNDO, THROW eSysError.
  END CATCH.

  FINALLY:
    /* Your code */
    MESSAGE "Inside FINALLY block." VIEW-AS ALERT-BOX BUTTONS OK.
  END FINALLY.
END. /* DO */

CATCH eSysError AS Progress.Lang.SysError:
  MESSAGE "Out of DO block and inside CATCH block for procedure block" 
    VIEW-AS ALERT-BOX BUTTONS OK.
END CATCH.

Notes

See also

CATCH statement, ON ERROR phrase, ON QUIT phrase, ON STOP phrase, RETURN statement