On Jan 24, 2025 at 8:38:25 AM, Nikolay Nikolov via fpc-pascal <
fpc-pascal@lists.freepascal.org> wrote:

> Maybe because there's a much better way to write it:
>
> procedure foo();
> var
>   s1: TStringList = nil;
>   s2: TStringList = nil;
>   s3: TStringList = nil;
> begin
>   try
>     s1:=TStringList.create;
>     s2:=TStringList.create;
>     s3:=TStringList.create;
>     doWhatever(s1,s2,s3);
>   finally
>     FreeAndNil(s3);
>     FreeAndNil(s2);
>     FreeAndNil(s1);
>   end;
> end;
>
> Best regards,
>
> Nikolay


I’ve basically never used try..finally in  my own code but I have seen
really ugly nested like about in other projects. This a down stream
consequence of exceptions right?

Regards,
    Ryan Joseph
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to