473,473 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

bad_alloc unhandled exception

Hi
Shouldn't this code cause a core dump when the sys runs out of mem,
when there's no default exception handling mechanism.

void fn()
{
SomeObj *so = NULL;
so = new SomeObj; // -> no mem? throws bad_alloc execption
// but if no one's catching it, then core
//dump?
if (so == NULL)
{ // perform exception handling

}
//etc...

}
Thanks!
Jon

Jul 23 '05 #1
3 2965
> Shouldn't this code cause a core dump when the sys runs out of mem,
when there's no default exception handling mechanism.
When an exception is thrown be never catched, terminate() is called
which must never return (meaning abort the program). Whether it causes
a core dump, brings you in the debugger or whatever is implementation
defined.
void fn()
{
SomeObj *so = NULL;
so = new SomeObj; // -> no mem? throws bad_alloc execption
// but if no one's catching it, then core
//dump?
if (so == NULL)
This will never be true.
{ // perform exception handling

}
//etc...

}


Note that you may change the default behavior by calling
set_terminate().

Jonathan

Jul 23 '05 #2
>>so = new SomeObj; // -> no mem? throws bad_alloc execption
// but if no one's catching it, then core
//dump?
if (so == NULL)
{ // perform exception handling

}
//etc...

exception handling is performed through try/catch block. new may never
return null, on failing.
try{
so = new SomeObj;
}
catch(bad_alloc &e)
{
////perform exception handling
}

Jul 23 '05 #3
Thanks ! in fact simulated a bad_alloc using setrlimit() to limit the
heap size for the proc... terminates()...

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jacek Dziedzic | last post by:
Hi! I accidentally did something like float *ptr = new float; where n was accidentally left uninitialized (and equal to something like -1073372080) and my program coredumped. I always...
5
by: Asfand Yar Qazi | last post by:
Hi, Just wondering, if I do a: std::set_new_handler(std::terminate) I won't have to worry about a std::bad_alloc being thrown when I do a 'new ...' or a 'new(nothrow) ...', right? Its...
0
by: Colmeister | last post by:
I recently read Jason Clark's excellent article on Unhandled Exceptions (http://msdn.microsoft.com/msdnmag/issues/04/06/NET/default.aspx) and have attempted to incorporate the features he talks...
3
by: schizoid_man | last post by:
Hi, I have the following code snippets and I get a std::bad_alloc error where I think there should be none. I've attached the relevant bits of the base class, derived class and the .cpp file...
1
by: michigaki | last post by:
Hi, we're currently working on a video streaming app. Here is the problem: int ConvertRGBtoYUV(int w, int h, unsigned char *rgb, unsigned int *yuv) { unsigned int *uu, *vv, *u, *v; unsigned...
4
by: Alerion | last post by:
Hello everyone, I've been a regular of this forum but this is my first post, generally I can find the answer to my question already, but this time I'm having a somewhat specific problem. For...
3
by: George2 | last post by:
Hello everyone, Please help to comment whether my following understanding is correct, 1. whether or not we are using auto_ptr to allocate new object on heap (using new), there may be...
6
by: George2 | last post by:
Hello everyone, I usually check whether there is bad_alloc thrown to identify whether the allocation is success or not. My question is, Is there a way to disable bad_alloc and just to...
3
by: arjor | last post by:
hello guys i get the following warning when i try to try an throw an exception given by the new command. declaration: void CopyTree(Vertex*& copy, const Vertex* originalTree)...
0
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,...
0
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
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
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
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
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.