[Lazarus] try finally exit

Ludo Brands ludo.brands at free.fr
Sat Jun 29 15:01:05 CEST 2013


On 06/29/2013 12:55 PM, Jürgen Hestermann wrote:

> 
> Is that the way programming is done today: "There is no documentation,
> just figure it out yourself"?
> I can't believe it.
> How can the programmer be sure that test results apply under all
> circumstances?
> Does he have to write test routines for all possible szenarious?
> What about nested try..finaly commands?
> Is it guaranteed that all finally parts are executed?
> 

Google for "freepascal try finally", first hit. Or in lazarus hit F1.
You get all the answers you need.

In case that is all too difficult and moaning on the ML is the preferred
way of getting information, here is the contents:

17.3 The try...finally statement
If no exception occurs inside the statement List, then the program runs
as if the Try, Finally and End keywords were not present, unless an exit
command is given: an exit command first executes all statements in the
finally blocks before actually exiting.
If, however, an exception occurs, the program flow is immediatly
transferred from the point where the excepion was raised to the first
statement of the Finally statements.
All statements after the finally keyword will be executed, and then the
exception will be automatically re-raised. Any statements between the
place where the exception was raised and the first statement of the
Finally Statements are skipped.
As an example consider the following routine:

Procedure Doit (Name : string);
Var F : Text;
begin
  Try
    Assign (F,Name);
    Rewrite (name);
    ... File handling ...
  Finally
    Close(F);
  end;
If during the execution of the file handling an execption occurs, then
program flow will continue at the close(F) statement, skipping any file
operations that might follow between the place where the exception was
raised, and the Close statement. If no exception occurred, all file
operations will be executed, and the file will be closed at the end.

 http://www.freepascal.org/docs-html/ref/refse99.html

Ludo




More information about the Lazarus mailing list