As we know*, a bad_alloc has the potential be thrown from pretty much anywhere and everywhere**. It seems to me at least that a bad_alloc is only thrown when the system is out of memory, though I may be wrong. If the system is that starved for resources, is it expected of our programs to try and recover from it? I mean, something is obviously very, very wrong if a modern system runs out of memory. How do most developers handle this situation?
* might know
**operator new / operator new[]
Thanks for your time,
Luc
*Edit - I ask this because I don't really want to add a 'throws std::bad_alloc' for every method that might throw it in my project documentation.
Usually programs don't try to recover from that. The best you could do is
catch std::bad_alloc in main() and perhaps do something there. That way
its only in one place.