Sujet : Re: encapsulating directory operations
De : Bonita.Montero (at) *nospam* gmail.com (Bonita Montero)
Groupes : comp.lang.cDate : 08. Jun 2025, 16:11:54
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <102497b$3tavs$3@raubtier-asyl.eternal-september.org>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
User-Agent : Mozilla Thunderbird
Am 07.06.2025 um 23:12 schrieb Janis Papanagnou:
> Context, in the general case, matters. ...
If you need the context then you catch the exception near where
it is thrown; but that's not usual, meaning in most cases you
don't need that context. F.e. when a bad_alloc is thown it dosn't
matter which allocation failed, it's just enough to know that a
memory-collapse happened.
It's been decades that I used C++, but back then in the 1990's
we did pass error context with the thrown error object.
You can easily define your own exception object with more context
but for 95% of all exceptions bad_alloc or system_error fit.
That's an inherent part of C++'s exception handling. If you use
standard error classes without context that's of course possible,
but nothing prevents you to define yet another error class derived
from some existing error class with additional information. You
are actually free to do what suits you and your projects best;
use rudimentary handling, or have a sophisticated error framework,
or anything in between.
Most exceptions you throw or catch are bad_allocs or system_errors.
With that you don't need any context. For the system_error it might
make sense to catch them nearer to the call level where the error
occured. Usually that happens with I/O-errors. But that still
doesn't need the context of the individual I/O-operation.