Sujet : Re: encapsulating directory operations
De : wyniijj5 (at) *nospam* gmail.com (wij)
Groupes : comp.lang.cDate : 07. Jun 2025, 19:43:25
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <1858c98adc50b2bec4021f15d0c5b94e2158f6b5.camel@gmail.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
User-Agent : Evolution 3.56.2 (3.56.2-1.fc42)
On Sat, 2025-06-07 at 18:31 +0200, Bonita Montero wrote:
Am 07.06.2025 um 13:58 schrieb wij:
C++ is no better, probably worse. Firstly, the term 'exception' (and
'vector' probably) is disabled in human mind to think about exception.
I deal with exceptions every day and I've no problems with that. C++
exceptions aren't that clean like Java exceptions, but still make much
less work than C return code handling.
The error from opendir(..):
EACCES Permission denied.
EBADF fd is not a valid file descriptor opened for reading.
EMFILE The per-process limit on the number of open file descriptors has
been reached.
ENFILE The system-wide limit on the total number of open files has been
reached.
ENOENT Directory does not exist, or name is an empty string.
ENOMEM Insufficient memory to complete the operation.
ENOTDIR name is not a directory.
...
Those are just common errors, there are actually more, and more from subsequent
read/write/.... File operations (particularily directory) are actually very nasty.
I think your 'less work' was from simplication or idealization, lots are
simplified and idealized.
We have no problem is because our average programs don't need to handle those
individual errors, but C's major task is to build OS, not average applications.
C++ had been trying to HIDE error (exception) from its beginning, very wrong
and very unsuccessful.
Exceptions are the cleanest way of error handling.
Conditional. As said 'simplified'.
In most cases you
deal with the error in a higher function and not in the leaf of the
call graph; therefore exceptions are perfect.
If you can handle errors that way, C can also do it in much simpler way.
The basic problem of throwing error is losing error context, it is similar
to set a global errno (or object) and cause the program to stack unwind.
C++ has many artificial fancy things and encourages such programming style.
Good or bad? Both, but I would say mostly bad.