[fpc-pascal] Freeing memory with exceptions
Steve Litt
slitt at troubleshooters.com
Mon May 22 20:37:45 CEST 2023
Michael Van Canneyt via fpc-pascal said on Sun, 21 May 2023 09:47:15
+0200 (CEST)
>Assuming the result of A is not used outside of Test, the following is
>the only solution:
>
>procedure Test;
>
>var
> A : TObject;
>begin
> A:=TObject.Create;
> Try
> // call some code in other unit which raise an exception
> DoThis;
> finally
> A.Free
> end;
>end;
Perhaps there could be one procedure that frees and unwinds everything,
since there will probably be more objects that need to be freed, and
this procedure could be called by every finally.
SteveT
Steve Litt
Autumn 2022 featured book: Thriving in Tough Times
http://www.troubleshooters.com/bookstore/thrive.htm
More information about the fpc-pascal
mailing list