473,503 Members | 2,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

Jul 22 '05 #1
3 1942

"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
Mike,

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

Jul 22 '05 #3
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1862
by: eas | last post by:
How to catch the following exceptions? Failure in an assignment operator Detection of an out-of-bound index in a user-defined array Range-checked access to a vector Any comments are...
21
7223
by: Stephan | last post by:
why does the following code not work???? after compiling and running it will just say killed after all my memory filled up any suggestions? #include <iostream> using namespace std; void...
6
3669
by: Ganesan selvaraj | last post by:
I using C# .net. i want to split the text files based of the some condition. my source text file size may be 4 kb to 4 gb. some time when i split the i got the "out of memory exception. when i...
6
2685
by: Fred Zwarts | last post by:
Hello, I am trying to debug some complex debug code. In order to track the use of dynamically allocated memory, I replaced the standard global new and delete operators. (Not for changing the...
5
1660
by: cpluszen | last post by:
Hi, I have developped a c++ class and I have used it in different programs without problems. Now, I'm modifying a c++ file developped by another person (it is a code example about how using a...
2
4028
by: jayapal | last post by:
Hi , I am using the NEW operator to allocate the memory in many places of my code.But I am not doing any error hadling or exception handling.Can any one suggests me how to do exception handling,...
27
2919
by: George2 | last post by:
Hello everyone, Should I delete memory pointed by pointer a if there is bad_alloc when allocating memory in memory pointed by pointer b? I am not sure whether there will be memory leak if I do...
3
1680
by: Daniel T. | last post by:
This is basically what I have now... class Foo { /* definition irrelevant */ }; istream& operator>>( istream& is, Foo& foo ); // could throw int main() { ifstream file( "file.txt" ); Foo...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5594
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5022
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.