Boost logo

Boost :

Subject: Re: [boost] Question for C++ experts about exception allocation failure
From: Jeffrey Bosboom (jbosboom_at_[hidden])
Date: 2009-05-16 22:36:24


Emil Dotchevski wrote:
> How is failure to allocate an exception object handled in various
> compilers? 15.1.4 says that "the memory for the temporary copy of the
> exception being thrown is allocated in an unspecified way" but I don't
> think it specifies behavior for the case when the allocation fails. I
> know that some compilers allocate exceptions from the heap, so does
> this mean that an attempt to throw any exception could, in theory,
> result in a std::bad_alloc being thrown instead? As far as I can tell
> such behavior wouldn't violate the C++ standard, but I'm not sure my
> interpretation is correct. Anyone?

Stroustrup, The C++ Programming Language, Special Edition, page 371:
"Throwing an exception requires an object to throw. A C++ implementation
is required to have enough spare memory to be able to throw bad_alloc in
case of memory exhaustion. However, it is possible that throwing some
other exception will cause memory exhaustion."

That seems to imply that in case of allocation failure when allocating an
exception, bad_alloc is thrown instead, although he stops short of saying
precisely that.

--Jeffrey Bosboom


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