Can the new operator throw an exception in real life?
And if so, do I have any options for handling such an exception apart from killing my application?
Update:
Do any real-world, new-heavy applications check for failure and recover when there is no memory?
The new operator, and new[] operator should throw
std::bad_alloc, but this is not always the case as the behavior can be sometimes overridden.One can use
std::set_new_handlerand suddenly something entirely different can happen than throwingstd::bad_alloc. Although the standard requires that the user either make memory available, abort, or throwstd::bad_alloc. But of course this may not be the case.Disclaimer: I am not suggesting to do this.