On 10/8/2020 9:34 AM, Juha Nieminen wrote:
>
daniel...@gmail.com <
daniel...@gmail.com> wrote:
>> I don't think so. If anything, I think the practice of disabling exceptions
>> has increased over the last decade, judging from reddit discussions,
>> requests for open source projects to support throws become calls to
>> std::terminate, and the extent to which projects have moved to
>> accommodate that.
>
> I think that error handling of any kind is almost non-existent in 99.9% of
> software projects out there (hobby or professional).
That's not my experience, for professional code including open source.
Obviously toy hobby programs don't matter.
>
> Look at pretty much any software project out there with source code
> available, be it C or C++, and you'll probably find zero error handling,
> for example related to running out of memory, or writing to a file
> failing for some reason. (Perhaps the only kind of error handling that
> you ever see is checking if opening a file succeeded or not, and even
> this only because it's so common to try to open a file that doesn't
> exist. I'm sure that if this were a very rare event, most programs
> wouldn't even bother doing that, and would happily misbehave if it
> ever happened.)
>
> I would bet that if you take almost any software out there that, for
> example, reads or writes files, it will not check for every read or
> write that it succeeded, or any other operation that it does (such as
> fseed() or ftell()). Heck, almost none of them probaby don't even bother
> checking if closing the file succeeded.
Ditto
>
> Of course one of the most likely scenarios for a catastrophic failure that
> a program may experience is running out of memory, and also one of the
> things that almost no program ever checks. In C this is particularly
> problematic because in principle you would need to make that check in
> myriads of places.
Not really. IME good projects tend to centralize OS calls, so you don't
find bare 'malloc' calls spread all over the code. They are rather
confined inside some wrapper or allocation module. There are multiple
reasons for this. One is error handling (could be as simple as log and
exit), another is performance, since these are expensive calls and the
design wants to keep them under control.
>
> The advantage of C++ exceptions is that it makes such checks much easier.
> You don't need to litter your code with hundreds and hundreds of checks to
> see if a memory allocation failed. Instead, you can strategically place
> a few catch blocks, and have the program report the problem and end
> gracefully if it happens.
>
> But, of course, 99.9% of C++ programmers don't bother doing that, no matter
> how easy it is. Just have the program crash for an unknown reason.
>
Again, not my experience.
But I see that this might be an habit for some Java and C# (.NET)
programmers - it's not that uncommon to find applications written in
those languages that more or less frequently prompt the user with some
incomprehensible message and terminate - very disappointing, and rude
(one of the reasons I like C++ better than those).
Apart of considerations on coding discipline, this may be an argument
against exceptions, since in those languages they are de facto the
/only/ error handling facility.