用法小demo,定义参见crt目录下的new头文件源码
#include <new> #include <cstddef> #include <cstdlib> #include <climits> #include <iostream> using namespace std; void __cdecl newhandler() { cout << "The new_handler is called:" << endl; throw bad_alloc(); return; } int main() { set_new_handler (newhandler); try { while (1) { new int[5000000]; cout << "Allocating 5000000 ints." << endl; } } catch ( exception e ) { cout << e.what() << " xxx" << endl; } return 0; }