Re: Fwd: What to do to get new users

Nikolay Nikolov via fpc-pascal <[email protected]>
Newsgroups gmane.comp.compilers.free-pascal.general
Message-ID <[email protected]>
On 1/24/25 7:16 AM, Hairy Pixels via fpc-pascal wrote:
> On Jan 24, 2025 at 11:20:02 AM, Nikolay Nikolov via fpc-pascal 
> <[email protected]> wrote:
>> 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
>>
>
> ok, I’ve never used exceptions in FPC except to mean actual exceptions 
> as in the program is corrupted so quit and exit.
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.
>
> 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).
>
> Feels to me like manual memory management and exceptions don’t mix well.

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.

Nikolay

_______________________________________________
fpc-pascal maillist  -  [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.