[fpc-pascal] why isn't the 'exit' in the finally end clause executed?

Dennis dec12 at avidsoft.com.hk
Sun Jun 23 09:08:19 CEST 2019


Using fpc 3.0.4, Lazarus 2.0, the following simple program

program tryfinally;

begin
   try
     Writeln('before finally');
   finally
      Writeln('inside finally. Before Exit');
      exit; //<----why isn't it executed?
   end;
   Writeln('after try finally block');

end.


gives


P:\RAM64>tryfinally.exe
before finally
inside finally. Before Exit
after try finally block



I have tried putting the try finally block inside a procedure, the same 
happened.
program tryfinally;

procedure Test;
begin
     try
       Writeln('before finally');
     finally
        Writeln('inside finally. Before Exit');
        exit;
     end;
     Writeln('after try finally block');
end;

begin
   Test;

end.

Dennis


More information about the fpc-pascal mailing list