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
> > 
> > <[email protected]> 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'd hate to see regular new not be allowed in nothrow 
functions. Having a way to allocate and return null on failure would definitely 
be a good feature for those trying to handle running out of memory, but for 
99.9999999% of programs, it's just better to throw the Error thereby killing 
the program and making it clear what happened.

- Jonathan M Davis

Reply via email to