<html><body><div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Jan 24, 2025 at 1:34:26 PM, Nikolay Nikolov via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> wrote:<br></div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" type="cite">
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.<br>Once you let them bubble up you need to wrap all call sites with try..finally right?<br>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:<br><br>var<br><br> {... initialize local vars you're going to allocate in this function with nil}<br><br>begin<br><br> try<br><br> {lots of code, allocations, calls, etc}<br><br> finally<br><br> {cleanup code}<br><br> {free stuff that isn't nil}<br><br> end;<br><br>end;<br><br>
</blockquote>
</div>
<div><br></div>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.<br>
<div dir="ltr">
<br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Regards,</div> Ryan Joseph</div></div><br>
</div></body></html>