CS202 5- ‹#›
Catching Exceptions with new
nvoid out_of_mem();             //user new handler callback
n
nint main() {
n  set_new_handler(out_of_mem); //install user new handler
n  while(true)
n    int *p = new int[1024];    //gobble up memory till gone
n  return (0);
n}
n
nvoid out_of_mem() {
n  cout <<"programmer supplied new handler called" <<endl;
n  //free up space & return, throw bad_alloc, abort, or exit
n  exit(1);
n}
n