[fpc-pascal] Fwd: What to do to get new users
Hairy Pixels
genericptr at gmail.com
Fri Jan 24 07:38:16 CET 2025
On Jan 24, 2025 at 1:34:26 PM, Nikolay Nikolov via fpc-pascal <
fpc-pascal at lists.freepascal.org> wrote:
> Doesn't matter whether they're handled in the same scope or not. It's the
> same code. Usually they're not handled in the same scope, but in a very
> distant place. That's usually when exceptions are convenient.
> Once you let them bubble up you need to wrap all call sites with
> try..finally right?
> Wrong. Only sites that allocate memory, that needs to be freed, before
> leaving the scope need a try..finally. You don't need to wrap every call.
> That's nonsense. The pattern is:
>
> var
>
> {... initialize local vars you're going to allocate in this function
> with nil}
>
> begin
>
> try
>
> {lots of code, allocations, calls, etc}
>
> finally
>
> {cleanup code}
>
> {free stuff that isn't nil}
>
> end;
>
> end;
>
>
Yes that’s what I meant. If you don't know which calls could fail you need
to wrap all functions that allocate memory in try..finally. That’s what the
original post was commenting on, the need for some other syntax which knows
to free a variable if the function terminates early due to an exception,
like the implicit exception frames for managed types like dynamic arrays.
Regards,
Ryan Joseph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20250124/ad4bf0a9/attachment.htm>
More information about the fpc-pascal
mailing list