Re: Exception handling Organization: unknown
And most importantly, WHEN is it allocated? It matters if the
of exceptions has to be robust -- what happens if there is not enough
to allocate the exception object? You can't throw bad_alloc, because
an object as well.
As I said, that does not matter. Exception object is (normally) not
allocated on the heap, but on the stack.
when say wat throw Something; the compiler will create a copy of Something
right away and throw that. It is the implementation's business where the
space is found for the base object, it can be a static area, but if the
class has a member like std::string, it gets copied the regular way.
Also, bad_alloc in
particular, is kinda like a POD, it's void of exceptions.
It's also a QoI issue, hopefully the compiler makes it so, or has a proper
In MFC the CMemoryException is also special and uses static memory. (and for
historical reasons not objects but pointers are thrown...)
(If by "out of memory" you also mean "out of stack", I think that you
are mistaken; stack is always considered as available. AFAIK there's
nothing available in the standard to treat stack exhaustion in any
The standard doesn't even know about 'stack', it is just a common
Doing that is +/- difficult in practice and platform dependent.
So IMO, stack exhaustion == crash.)
And a nasty one too, as usual optimizer settings include 'omit frame
pointer' and especially the check of stack space at function entry -- so the
program will just write to the memory locations. That with luck are
pagefaulting, but as well may just belong to some existing object...
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]