How can you tell when a multimap insertion fails due to Out Of Memory

iyac
iyac used Ask the Experts™
on
Quite simply, how can you tell when a multimap insertion fails due to running out of memory?  I expected that this would be easily found on Google but have had no luck.  My two guesses would be that it would return end() or that it would throw an exception but I haven't managed to find anything definitive.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Nope it will definitely not return end() because of an out of memory condition. I'm saying this because thats not a general design strategy in STL. The world is divided wrt whether new operator would throw std::bad_alloc when it fails to allocate memory or not. STL variant that favor exceptions - possibly this behavior is configurable - you can expect a std::bad_alloc exception. For others, I'm not sure - but i think it will just crash.

For example, VisualStudio has the define

#define _HAS_EXCEPTIONS 1

If you set this to 0 it will not throw std::bad_alloc.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial