Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2022-05-30 01:50:09


On 5/28/22 3:39 PM, Andrzej Krzemienski via Boost wrote:
> try {
>> lib::function();
>> }
>> catch(lib::exception const&) {
>> // handle failure
>> }
>>

Pretty good and reasonable answers. These seem to boil down to, any
kind of failure in lib::function (or below) we would handle at the point
of failure hence if we need to throw an exception we've skipped over a
failure case. (paraphrasing - still not sure I get it).

I'm envisioning some that I think happens to me on a regular base.
Inside of lib::function (or lower) I request a large memory allocation
which I expect to almost never fail. I can trap this failure. If I
return failure at each call up the chain, I end up doing a lot of "if"
at each level making the code slower and messier. And this slowness
messiness happens even on cases where there is no failure. I don't have
exceptions in this scenario.

What I actually do in this case is throw a custom exception at the point
of failure which gives me information of where I was and what I was
doing when I requested this "too large" memory allocation. This seems
to be a very reasonable scenario to me.

Robert Ramey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk