FreePascal Information Logo Friend of FreePascal Compiler Title
Articles with Feedback, FPC News Library, PDF Collection, Mail Lists, Books, Newsgroups, IRC Open online discussion areas Research and Tutorials Tools, Compilers and Utilities Blurbs about us, advertising, etc.
Welcome to the FoFPC Pascal Language FINALLY

finally


     The Finally keyword is used to mark the start of the final block of statements in a Try statement. They are executed regardless of what happens in the Try statements.

     However, the Finally clause does not actually handle any exceptions - the program will terminate if no Except clause is found.

     Try-Finally is normally used by a routine to guarantee the cleanup processing takes place, such as freeing resources, with the exception being correctly passed to the caller to handle.

Try
   ... code which my raise an exception ...
Except
   ... to handle and/or report an exception ...
Finally
   ... code to clean-up connections, resource ...
End;


Example

    Download Source IconDownload This Source for Free Pascal
{$MODE DELPHI} // Enable Try/Finally keywords

var
  number, zero : Integer;

begin
  // Try to divide an integer by zero - to raise an exception
  number := -1;
  Try
    zero   := 0;
    number := 1 div zero;
    Writeln('number / zero = ',number);
  Finally
    if number = -1 then begin
      Writeln('Number was not assigned a value - using default');
      number := 0;
    end;
  end;
end.

Output

Number was not assigned a value - using default
Runtime error 200 at $080480C2
  $080480C2
  $0805F3F1

See Also

Except, On, Raise, Try.
 Links and Products we find useful



ButtonGenerator.com
Valid XHTML 1.0 Transitional Internet Map
Programmer's Heaven
grat-i-fi-ca-tion - noun
the state of being gratified; great satisfaction.


"FoFPC is simply brilliant, a single site with exactly what I was looking for - you made this so easy for me!"

Doug Edwards
eXtreme Accounting
Locations of visitors to this page world map hits counter
Copyright 2009 by 3F, LLC. All rights reserved. Worldwide.
Your request was processed by server #3 in 0.001602 secs.

sponsor
This sponsor helps us with our documentation