<html><body><div class="gmail_quote">
    <div dir="ltr" class="gmail_attr">On Jan 24, 2025 at 12:43:51 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">
        That's not what exceptions are meant to be used for, though. What you describe is called a program "defect". When you encounter a "defect" in your program, you terminate the program. The proper handling of a defect is to fix (modify) the program, so it doesn't happen again. In the case of a "defect", there's no much point in freeing the memory, because all of the program's memory is freed anyway, when the process terminates. An exception is used for reporting an unanticipated condition, encountered at runtime. A program can be correct (bug free) and still encounter exceptions. For example, a web browser might encounter a network error, during the loading of a web page, in which case, it should report the error to the user in its GUI, and it should continue operating normally, instead of crashing, so the user can continue browsing, by e.g. trying again, or typing in a different URL, or switching to a different tab, etc.<br></blockquote><div class="gmail_quote"><br></div><div class="gmail_quote" dir="ltr">Yes I know I’m just saying that’s the most I’ve done with them in Pascal. I do use them to escape deep recursion too and then they’re very helpful but I would have random allocations in a recursive that could fail randomly at any point.</div><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" type="cite">Feels to me like manual memory management and exceptions don’t mix well.<br>I fail to understand how you came to this conclusion, since I just showed how the same code would look without exceptions, and it's way worse.<br><br></blockquote><div class="gmail_quote"><br></div><div dir="ltr">That example was the best scenario for exceptions where they’re handled in the same scope they occur and they don’t bubble up through the call stack. Once you let them bubble up you need to wrap all call sites with try..finally right? I think that’s what I’ve seen.</div>
</div>
<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>