But the sad truth is that if a memory allocation fails, there's usually not much left that the program can do except terminate.
While (true), there is always the option to (prompt the user to free up some resources and retry) or (terminate the application). Just something to think about. (Note: I'm not arguing for or against any of this discussion; this is just a potential option to consider if you would like to handle an allocation exception.)