471,309 Members | 932 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,309 software developers and data experts.

how to handle the exception handling when NEW operator failed to allocate memory

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, which code part I
have to add to do the exception handling

Thanks in advance,

..

Jul 17 '07 #1
2 3860
jayapal wrote:
I am using the NEW operator
I believe you mean the "new operator" (C++ is case sensitive).
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, which code part I
have to add to do the exception handling
What book on C++ are you reading that doesn't give any "suggestions"?

Error handling and exceptions are not the same thing nor they have the
same purpose. Books have been written to try to explain those concepts
and not many actually succeed, unfortunately. Start with chapter 14
in TC++PL. Then ask more question if you get any.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 17 '07 #2
On Jul 17, 5:16 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
jayapal wrote:
I am using the NEW operator

I believe you mean the "new operator" (C++ is case sensitive).
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, which code part I
have to add to do the exception handling

What book on C++ are you reading that doesn't give any "suggestions"?

Error handling and exceptions are not the same thing nor they have the
same purpose. Books have been written to try to explain those concepts
and not many actually succeed, unfortunately. Start with chapter 14
in TC++PL. Then ask more question if you get any.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


Hi,

I worked too hard to find the solution and found that this is a
standard exception which is thrown by new itself.

// bad_alloc standard exception
#include <iostream>
#include <exception>
using namespace std;

int main () {
try
{
int* myarray= new int[1000];
}
catch (exception& e)
{
cout << "Standard exception: " << e.what() << endl;
}
return 0;
}

--
Regards
Mayank Jain
Niksun
9818390836
www.mayankjain.110mb.com

Jul 18 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

27 posts views Thread by garyolsen | last post: by
10 posts views Thread by Steven T. Hatton | last post: by
2 posts views Thread by dinks | last post: by
10 posts views Thread by Neelesh Bodas | last post: by
3 posts views Thread by clintonb | last post: by
6 posts views Thread by Liming | last post: by
6 posts views Thread by asm23 | last post: by
reply views Thread by rosydwin | last post: by

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.