[fpc-pascal] Freeing memory with exceptions

Hairy Pixels genericptr at gmail.com
Thu May 25 04:31:42 CEST 2023



> On May 24, 2023, at 8:46 PM, Michael Van Canneyt via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> 
> I see no problem, I am used to this.
> 
> This is Pascal, you need to manage your memory and hence your references, this is true even in the absence of exceptions: In your example you would
> also need to remember to remove your instance from the list after you free
> it, even if there are no exceptions.

My example is still not good. The problem I have is that once exceptions are used in a program calling any function now has a side effect of completely exiting the calling function so you need to be paranoid and wrap everything in try blocks just in case. A new added burden for manual memory management.

Why is this better than handling errors as values like a normal function result?

Rust is maybe the most major language which has not implemented exceptions but I'm seeing other new experimental languages go this way also. I've only used them in C# and Swift which are fully ARC but they appear to be  a bad idea the industry is going against now after years of experience. 

Regards,
Ryan Joseph



More information about the fpc-pascal mailing list