Difference between revisions of "Finally"

From Lazarus wiki
Jump to navigationJump to search
m (Fixed syntax highlighting; improved English translation of German)
Line 1: Line 1:
 
{{Finally}}
 
{{Finally}}
  
The [[Reserved word]] <syntaxhighlight lang="pascal" enclose="none">finally</syntaxhighlight> identifies the [[Block|block]] that should always be processed, regardless of whether an error has occurred or not.
 
  
Example:
+
Back to [[Reserved words]].
<syntaxhighlight>
+
 
 +
 
 +
The reserved word <syntaxhighlight lang="pascal" enclose="none">finally</syntaxhighlight> identifies a [[Block|block]] of code that should always be processed, regardless of whether an error has occurred or not.
 +
 
 +
== Examples ==
 +
 
 +
Simple example:
 +
 
 +
<syntaxhighlight lang=pascal>
 
begin
 
begin
 
   ...
 
   ...
 
   try
 
   try
     ... // Action
+
     ...   // code to check
 
   finally
 
   finally
     ... // Final work, which should be done even in case of error
+
     ...   // code which should always be executed even in case of error
 
   end;
 
   end;
 
   ...
 
   ...
Line 16: Line 23:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
Example with error handling:
  
Example (in this example, the <syntaxhighlight lang="pascal" enclose="none">finally</syntaxhighlight> block is always executed):
+
<syntaxhighlight lang=pascal>
 
 
<syntaxhighlight>
 
 
begin
 
begin
 
   ...
 
   ...
 
   try
 
   try
 
     try
 
     try
       ... // instructions to check
+
       ... // code to check
     except // error handling
+
     except  
       ...
+
       ... // error handling
 
     end;
 
     end;
   finally // always instructions to be processed
+
   finally
     ...
+
     ...   // code which must always be executed even in case of error
 
   end;
 
   end;
 
   ...
 
   ...

Revision as of 00:50, 16 February 2020

Deutsch (de) English (en) suomi (fi)


Back to Reserved words.


The reserved word finally identifies a block of code that should always be processed, regardless of whether an error has occurred or not.

Examples

Simple example:

begin
  ...
  try
    ...    // code to check
  finally
    ...    // code which should always be executed even in case of error
  end;
  ...
end;

Example with error handling:

begin
  ...
  try
    try
      ...  // code to check
    except 
      ...  // error handling
    end;
  finally  
    ...    // code which must always be executed even in case of error
  end;
  ...
end;

See also