By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

when memory exhaust,how we can catch the new operator exception.

P: n/a
when memory exhaust,how we can catch the new operator exception.

Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"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

Jul 22 '05 #2

P: n/a
Mike,

If I don't use Sun C++ 4.2, how to catch the new error.
Thanks,
Alex Wang.

Jul 22 '05 #3

P: n/a
"8519428 Wang Tian-da Alex" <wa********@lucent.com> wrote in message
news:bq********@netnews.proxy.lucent.com...
Mike,

If I don't use Sun C++ 4.2, how to catch the new error.


The code I posted will work with any standard-compliant
compiler.

-Mike
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.