[fpc-pascal] Halt() bypassed try..finally block

Matt Emson memsom at interalpha.co.uk
Thu Sep 13 12:11:32 CEST 2007


Michael Van Canneyt wrote:
> On Thu, 13 Sep 2007, Graeme Geldenhuys wrote:
>
>   
>> Hi,
>>
>> Is that correct behavior?  When calling Halt() somewhere inside a
>> try..finally block, it _doesn't_ execute the finally code.
>>     
>
> This is by design.
>
> Halt finalizes the units and then exits.
Yeah, I always used to use something like:

var
  haltApp: boolean;
begin

haltApp := false;

try
  //some code that does something
  if (some_condition) then
  begin
    haltApp := true;
    exit;
  end;
  //some other code
finally
  //cleanup code

  if (haltApp) then Halt(halt_condition_code); // one could argue this 
should be outside of the finally,
                                                                     // 
but if it were it would not always be executed as
                                                                     // 
desired - especially if an exception was raised. 
end;



More information about the fpc-pascal mailing list