[fpc-devel] Different handling of try..except depending on OS?

Bart bartjunk64 at gmail.com
Wed Dec 9 23:45:21 CET 2020


Hi,

Consider this code:

program Test;
{$apptype console}
{$ifdef fpc}
{$mode objfpc}
{$endif fpc}
{$R+}

var
  Arr: array[1..2] of integer;
  i: Integer;
begin
  i:=5;
  try
    try
      Arr[i] := 1;
    except
      writeln('Except block');
    end;
  finally
    writeln('Finally block');
  end;
end.

Compiled with fpc 3.2.0 on Windows it will output (both 32 and 64 bit):
Runtime error 201 at $004015F1
  $004015F1
  $00407307

Compiled with fpc 3.2.0 on linux X86_64 it will output
Except block
Finally block

On Windows you need to include the sysutils unit to execute the except
and finally block.

Note 1:  fpc 3.0.4 on Windows generates the same outpus as 3.2.0 on Linux...
Note 2: Delphi 7 behaves like 3.2.0

Is there any explanation for that?
Related forum discussion:
https://forum.lazarus.freepascal.org/index.php/topic,52469.0/topicseen.html

-- 
Bart


More information about the fpc-devel mailing list