TRY guarded-statements FINALLY cleanup-statements END
The TRY-FINALLY statement guarantees that cleanup-statements are called, no matter what happens in the guarded-statements. If there was an exception raised in the guarded-statements, then the same exception is re-raised by TRY-FINALLY.
Note: The TRY-FINALLY statement catches internal exceptions raised by all EXIT and RETURN statements.
TRY-FINALLY is quite useful for clean-up activities, like closing file handles:
rd := IO.OpenRead("myfile"); TRY WHILE NOT EOF(rd) DO IO.PutLine (IO.GetLine(rd)); END; FINALLY Rd.Close(rd); END;