Re: crash when run out of memory
From: Ali Çehreli (acehreli_at_yahoo.com)
Date: 11/06/04
- Next message: David Lindauer: "Re: comma"
- Previous message: G. S. Hayes: "Re: Not STD C is "not C" ? ----WAS: Re: C to Java Byte Code"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 5 Nov 2004 15:17:24 -0800
"jy" <jy_austin@yahoo.com> wrote in message
news:fa63e07d.0410291311.1239979c@posting.google.com...
> I have a C++ program which is "purify" clean, but crashes (called
terminate)
> when run out of memory on linux 2.4.27. From the core file, the crashes
happen
> after I throw an exception (after malloc returns null),
I think it is new that throws the exception, not you. new is likely
using malloc internally and throwing std::bad_alloc when there is no
memory.
> and the stack winding
> was calling the destructor of a large object. What's the genearl guidlines
for
> debugging, fixing, or at least making it a graceful exit than a crash?
Catch std::bad_alloc exception in main and report it:
int main()
{
try
{
/* the application code */
}
catch (std::bad_alloc const &)
{
cout << "no memory\n";
}
}
Ali
- Next message: David Lindauer: "Re: comma"
- Previous message: G. S. Hayes: "Re: Not STD C is "not C" ? ----WAS: Re: C to Java Byte Code"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|