How can I convince my (older) compiler to automatically check new to see if it returns NULL?
[Recently fixed bugs: new handlers don’t take arguments, thanks to Scott Aaron; changed set_new_hanlder to set_new_handler, thanks to Peter Andersson (on 1/97). Click here to go to the next FAQ in the “chain” of recent changes.] Eventually your compiler will. If you have an old compiler that doesn’t automagically perform the NULL test, you can force the runtime system to do the test by installing a “new handler” function. Your “new handler” function can do anything you want, such as print a message and abort() the program, delete some objects and return (in which case operator new will retry the allocation), throw an exception, etc. Here’s a sample “new handler” that prints a message and calls abort().