Use nothrow to force new not to generate exception.(Although it wont work with old headers). Another way to handle errors is to use set_new_handler() from new or new.h
Headers.
Code with new.h compiles in my PC but generates an assertion fail and doesn't work.
Code:
void errh(void);
const int arlmt=10000;
long double *v[arlmt];
const int ind =10000000;
main()
{
set_new_handler(errh);
int nfaloc=0;
int sum=0;
for(int s=1;s<arlmt;s++)
{
v[s]=new long double[ind/s];
if(v[s])
{
for(int i=0;i<ind/s;i++) *(v[s]+i)=(long double)i;
sum+=(ind/s);
int fortest=0;
cout<< ((ind/s)*8)/(1024)
<<" KBs at "<< v[s]
<<" Test: ";
for(i=0;i<ind/s;i++) {
if(*(v[s]+i)!=(long double)i) {fortest=1;break;}
}
if(fortest==1) cout<<"Failed. ";
else cout<<"OK. ";
cout << "Total: "<<(sum*8)/(1024*1024)<<" MBs allocated and tested."<<endl;
}
else
nfaloc++;
}
cout<<nfaloc<<" Number of allocations failed!"<<endl;
cout<< "Press a key..." <<endl;
getch();
return 0;
}
void errh(void)
{
cout<<"ERR allocating!"<<endl;
}
Clear?