#include <iostream>
#if (_WIN32 && _MSC_VER && _MSC_VER <= 1200)
#include <new.h>
int my_new_handler(size_t)
{
throw std::bad_alloc();
}
#else
#include <new>
void my_new_handler(void)
{
throw std::bad_alloc();
}
endif
int main(void)
{
// Install our "out of memory" handler
#if (_WIN32 && _MSC_VER && _MSC_VER <= 1200)
_set_new_handler(my_new_handler);
#else
std::set_new_handler(my_new_handler);
#endif
char *p = 0;
try {
p = ::new char[1000 * 1000 * 1000 * 2];
}
catch (std::exception &e) {
std::cout << e.what() << std::endl;
}
if (p)
return 0;
else
return -1;
}