The FINALLY statement creates an end block that executes once at the end of each iteration of its associated block, regardless of whether the associated block executed successfully or raised a condition.

The FINALLY block executes after:

  • Successful execution of the associated block.
  • Each successful iteration of an iterating associated block.
  • ERROR or STOP is raised in the associated block regardless of whether a CATCH block or ON phrase handles the condition.

The FINALLY block does not execute if:

  • A QUIT statement is in effect and it is not handled.

Since a FINALLY block executes after an invoked CATCH block, it can also be used to perform common post-CATCH cleanup tasks, rather than repeating common code in all the CATCH blocks present in the associated block.