On Jan 5, 6:06 pm, red floyd <no.s...@here.dude> wrote:
> Roland Pibinger wrote:
> > On Fri, 05 Jan 2007 15:46:42 +0200, Chameleon wrote:
> >> I am confused on this:
> >> When "new" fails, what happens?
> >> - throws bad_alloc
> >> - returns 0
>
> > Most probably neither nor. operator new allocates memory and calls a
> > constructor. If construction fails a constructor specific exception is
> > (better, may be) thrown. Out of memory is usually handled by a
> > new_handler that just terminates the application (you cannot 'handle'
> > out of memory). The std::bad_alloc exception is a textbook artefact
> > that is never seen in the real world.No, bad_alloc is mandated by the Standard. Just because *you* aren't
> using standard-compliant compiler, don't assume the same for the rest of us.
That was the impression I got from reading the online Dinkumware C++
documentation.
To the orginal poster, the dinkumware site gives a very good
description of this.
Just search on "new handler". Also, Meyer's Effective C++, 3rd
Edition, goes
over this in great detail.
|