topical media & game development

talk show tell print

professional-program-15-NewFailures-NewHandler.c

? / professional-program-15-NewFailures-NewHandler.c


  include <new>
  include <cstdlib>
  include <iostream>
  
  using namespace std;
  
  void myNewHandler()
  {
    cerr << "Unable to allocate memory. Terminating program!\n";
    abort();
  }
  
  int main(int argc, char** argv)
  {
    // code omitted
  
    // Set the new new_handler and save the old.
    new_handler oldHandler = set_new_handler(myNewHandler);
    // code that calls new
  
    // reset the old new_handler
    set_new_handler(oldHandler);
    // code omitted
    return (0);
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.