473,498 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4027
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
3389
by: garyolsen | last post by:
In C++ what kind of unexpected conditions should be handled as exceptions? Besides dividing by 0, bad memory allocation, what're the most popular exceptions? When should not use exception,...
10
2032
by: Steven T. Hatton | last post by:
I read Stroustrup's article of the day: http://www.research.att.com/~bs/C++.html Programming with Exceptions. InformIt.com. April 2001. http://www.research.att.com/~bs/eh_brief.pdf Some of...
2
2020
by: dinks | last post by:
Hi, I'm new to C++ and have been assigned a task which i dont completely understand. Any help would be greately appreciated. Here is the problem: The class "linkedListType" use the "assert"...
6
2682
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...
10
2560
by: Neelesh Bodas | last post by:
Hi all, suppose the ctor of the class throws. Thus, at this point in time, some memory has been allocated but the object couldnot be constructed. Also, the memory is not yet freed. Does the c++...
3
2014
by: clintonb | last post by:
Some programmers, and even Microsoft documents, say you should only throw exceptions for exceptional situations. So how are others handling all the other unexceptional errors? How are you...
6
2029
by: Liming | last post by:
Hi, In a typical 3 tier model (view layer, busines layer and data access layer) where do you handle your exceptions? do you let it buble up all the way to the .aspx pages or do you handle it in...
1
292
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,...
6
218
by: asm23 | last post by:
Hi, everyone, I'm learning <<thinking c++>volume Two, and testing the code below. ///////////////////////////////////////////////////////////////////////////// //: C01:Wrapped.cpp #include...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7004
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
7167
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6890
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
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5464
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
4915
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
4593
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.