new没有抛出异常(vc6.0 and xp)
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
try{
char *pbigdataarray = new char[10000000000000000000ul];
if(pbigdataarray==NULL)
cout<<"wrong"<<endl;
}
catch(bad_alloc a)
{
cout<<"jfjl"<<endl;
}
catch(...)
{
cout<<"cdfc"<<endl;
}
return 0;
}
/***************/
解答:
在未标准化时,c++中的new运算符总是返回NULL表示分配失败,就像malloc那样。标准C++修订了new的语义,plain new在失败后抛出标准异常std::bad_alloc而不是返回NULL。故,采用的可能是未标准化的c++。