On Wednesday, 6 June 2012 at 18:11:42 UTC, Jonathan M Davis wrote:
On Wednesday, June 06, 2012 19:22:13 Lars T. Kyllingstad wrote:
On Wednesday, 6 June 2012 at 09:38:35 UTC, Jonathan M Davis
wrote:
> On Wednesday, June 06, 2012 11:13:39 Lars T. Kyllingstad
> wrote:
>> On Friday, 1 June 2012 at 12:29:27 UTC, Steven Schveighoffer
>>
>> wrote:
>> > On Fri, 01 Jun 2012 04:48:27 -0400, Dmitry Olshansky
>> >
>> > <dmitry.o...@gmail.com> wrote:
>> >> I don't agree that OutOfMemory is critical:
>> >> --> make it an exception ?
>> >
>> > No. What we need is a non-throwing version of malloc that
>> > returns NULL. (throwing version can wrap this). If you
>> > want
>> > to throw an exception, then throw it there (or use
>> > enforce).
>>
>> With some sugar:
>> auto a = nothrow new Foo; // Returns null on OOM
>>
>> Then, ordinary new can be disallowed in nothrow code.
>
> But then instead of getting a nice, clear, OutOfMemoryError,
> you get a
> segfault - and that's assuming that it gets dereferenced
> anywhere near where
> it's allocated. [...]
I agree; it would make nothrow an "advanced feature", which
kind
of sucks.
Which makes the suggestion DOA IMHO.
I'm not so sure it's worse than the current situation.
Newbie: "This nothrow thing looks kinda cool. So, if I use it,
I can be sure nothing gets thrown from this function, right?"
Community: "Right. Unless you run out of memory, or an
assertion fails, or something like that. Then you get an Error,
and nothrow doesn't prevent those."
Newbie: "Ok, I guess that makes sense. Luckily, it looks like
Error is just another kind of exception, so at least I know that
all my destructors are run and my program terminates gracefully.
Right?"
Community: "Yeah, about that..."