"<- Chameleon ->" <cham_gss@hotmail.NOSPAM.com> wrote in message
news:bqicd9$50a$1@nic.grnet.gr...
I have this code:
---------------------
try {
int *a = new int[1000000000];
} catch (...)
{
cout << "oh no!"; exit(0);
}
----------------------
new returns 0 but no exception occur in this error. Why?
============
I learn today about auto_ptr. What is the use of this? (I have not
understand it well)
if I want automatic deletion of int array inside a class constructor
on
exception I must use it like this?
-------------------------
auto_ptr<int> array_of_int(new int(100));
-------------------------
The compiler I use (cxx) throws an exception only if the source code
is
compiled with an option to the compiler telling it to use std new.
Otherwise, 0 is returned instead of throwing an exception. You
probably
need to tell your compiler to use std new.
above of this code I use
using namespace std;
No. auto_ptr is not for arrays. The destructor calls delete, not
delete[].
As for the lack of exception on new , what compiler are you using? You
also could look specifically for a std::bad_alloc exception.
I use MS VC++ 6
VC++6 default behavior upon failure of operator new is
nonstandard (but there is a way to work around that).
See: http://tinyurl.com/xef9
-Mike
.