Boost logo

Boost :

Subject: Re: [boost] Question for C++ experts about exception allocation failure
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2009-05-17 14:10:09

On Sun, May 17, 2009 at 1:53 AM, Sebastian Redl
<sebastian.redl_at_[hidden]> wrote:
> 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?
> MSVC allocates on the stack.

Now that you mention this, I remember something else I was wondering
about MSVC: is the code in the exception handler executed on top of
the stack, just over the exception object that was put there by the

Also, you could run out of stack memory. It's likely that in this case
you'll get abort() just like when you run out of memory for exceptions
in GCC, unless you have structured exception handling enabled -- and
in that case would you get some sort of stack overflow exception?

Emil Dotchevski
Reverge Studios, Inc.

Boost list run by bdawes at, gregod at, cpdaniel at, john at