TRY ... FINALLY

Top  Previous  Next

Creates a block of statements and makes sure there's a one or more statements that will be executed even when an exception occurs.

 

Syntax

<try_finally_block> ::= 

  TRY

    [<compound_statement>]

  FINALLY

    [<compound_statement>]

  END

 

<compound_statement> ::= {<block> | <statement>}

 

When an exception occurs between TRY and FINALLY, executing that list of statement is stopped and the statements in the FINALLY clause will be executed. The exception is escalated to the parent block.

 

If no exception occurs between TRY and FINALLY, all statements will be executed and afterwards, all statements in the FINALLY clause will be executed.

 

See Also

BEGIN ... END-block
TRY ... EXCEPT

 

Example

execute udsblock()

returns(v1 integer, v2 integer)

AS

begin

  try

    v1 = 10;

    v2 = 10;

    try

      exception TEST_EXCEPTION; /* force an exception to occur */ 

      v2 = 11; /* not executed, because an exception occured */

    finally  /* FINALLY block will be executed despite exception */

      v2 = 14;

    end

  except /* exception handler will be executed because of the exception */ 

    v1 = 14;

  end

  /* normal execution resumes as the exception was caught */

end