[fpc-devel] Defer keyword

J. Gareth Moreton gareth at moreton-family.com
Thu May 6 20:02:53 CEST 2021


The rule with try...finally is that, outside of something completely 
catastrophic that destroys the program flow, is that once you enter the 
try part, the finally part is guaranteed to be executed no matter how 
you leave it.

Gareth aka. Kit

On 06/05/2021 18:53, Ryan Joseph via fpc-devel wrote:
>
>> On May 6, 2021, at 11:39 AM, J. Gareth Moreton via fpc-devel <fpc-devel at lists.freepascal.org> wrote:
>>
>> In the example given:
>>
>>   obj := TObject.Create;
>>   defer objects.Free;
>>
>> What's wrong with Pascal's existing functionality?
>>
>>   obj := TObject.Create;
>>   try
>>     ...
>>   finally
>>     objects.Free;
>>   end;
>>
>> If there's a concern about performance penalty, maybe the compiler can work something out for simple finally blocks and just copy the code to any Exit nodes found rather than calling the pseudo-procedure that a try...finally block creates.
> I didn't know try..finally even worked like that. :) I thought it was just for exceptions but I see it captures exit also. The defer keyword is nicer on the eyes I would say because it don't require wrapping the entire function in a big block of code.
>
> So never mind then I guess. I'll start using try..finally and see how that works for me.
>
> Regards,
> 	Ryan Joseph
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>

-- 
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



More information about the fpc-devel mailing list