Boost logo

Boost :

Subject: Re: [boost] expected/result/etc
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2016-02-11 00:23:10


On 11/02/2016 15:08, Emil Dotchevski wrote:
> Dereferencing a null shared_ptr is something that easily could happen at
> runtime. Are you saying that it shouldn't assert in this case? Are you
> saying that that assert is useless? Are you saying that the correct design
> is to throw? Or is the correct design to assert and throw?

I answered that in the next paragraph:

On 11/02/2016 14:11, I wrote:
> You could assert *and* throw (or abort, if you don't know how to
> recover from it), although arguably the assert is less useful if
> you're repeating the same condition outside the assert anyway. But
> you can't just slap an assert in and call it a day, at least not for
> this sort of condition.

Or you could just throw. I'm not convinced that the assert itself adds
any particular value, aside from possibly being more in-your-face when
running a debug build. (But thrown exceptions can be equally in your
face in both debug and release builds if you have a debugger attached,
and if throwing exceptions is unusual so you haven't disabled "break on
exception throw".)


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