"8519428 Wang Tian-da Alex" <wa********@lucent.com> wrote in message
news:bq********@netnews.proxy.lucent.com...
when memory exhaust,how we can catch the new operator exception.
#include <iostream>
#include <new>
int main()
{
const size_t elem_count(1000);
const size_t elem_size(1000);
char *p = 0;
try
{
p = new char[elem_count * elem_size];
}
catch(std::bad_alloc& e)
{
std::cerr << e.what() << '\n';
return EXIT_FAILURE;
}
delete[] p;
return EXIT_SUCCESS;
}
-Mike