<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 1/24/25 7:16 AM, Hairy Pixels via
fpc-pascal wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAGsUGtnUQd1U6N+YNC0e7O_sODEAcVZmUs_ngi8c4Kz9sLWevA@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Jan 24, 2025 at
11:20:02 AM, Nikolay Nikolov via fpc-pascal <<a
href="mailto:fpc-pascal@lists.freepascal.org"
moz-do-not-send="true" class="moz-txt-link-freetext">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"> As you can see, it's more complicated and more
error prone. You can simplify it a little bit with goto, but
it will never be better, compared to try...finally<br>
<br>
</blockquote>
</div>
<br>
<div dir="ltr">ok, I’ve never used exceptions in FPC except to
mean actual exceptions as in the program is corrupted so quit
and exit.</div>
</blockquote>
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 type="cite"
cite="mid:CAGsUGtnUQd1U6N+YNC0e7O_sODEAcVZmUs_ngi8c4Kz9sLWevA@mail.gmail.com">
<div dir="ltr"><br>
</div>
<div dir="ltr">I’ve seen other people put these all over their
code though. I guess the idea is that they’re trying to recover
from exceptions and so they need to wrap literally every single
function that could fail anywhere with try…finally. I don’t have
any examples but I think I’ve seen this (feel free to post any
if people could think of some from real projects).</div>
<div dir="ltr"><br>
</div>
<div dir="ltr">Feels to me like manual memory management and
exceptions don’t mix well.</div>
</blockquote>
<p>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.</p>
<p>Nikolay<br>
</p>
<br>
</body>
</html>