[Exceptional C++ Style] Item 22: To new, Perchance to throw, Part 2: Pragmatic Issues in Memory Management

Balog Pal pasa at lib.hu
Thu Jan 20 06:36:22 EST 2005


> It's possibly worth emphasizing that said stack unwinding often allows an
> application to continue to run without problems. I've often heard it said
> that memory allocation failures are best handled by termination of the
> program as all is lost... For many applications, failing the operation
> cleanly and being ready to perform the next one is perfectly acceptable
> behaviour. Provided that your libraries and application code all behave
> properly, that is.

IMHO the best thing to do on windows-like interactive systems is to just 
stall. Mean keep retrying the allocation calling Sleep().  There's no need 
even to report the problem, as the system will alert. The user will close 
some stuff then get chance to continue without loss. Or he can kill the 
program if it is the only thing possible.

And new-handler can be used easily to force that tactic, then new really 
can't fail. 




More information about the Effective-cpp mailing list