PreviousNextIndex

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 the 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
finally-logic
block-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 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

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


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex