There is such code:
#include <iostream>
int main(){
for(;;){
int* ptr = new (std::nothrow) int;
if(ptr == 0){
std::cout << 0 << std::endl;
break;
}
}
std::cin.get();
return 0;
}
However, this program still throws std::bac_alloc exception, altough new is called with std::nothrow parameter. This program is compiled in Visual C++ 2010. Why the exception is thrown?
Edit:
Using g++ on Windows from mingw, everything works ok.
#include <new>
. Anyway, what version of VC++ are you using? – Clothingulimit
to something small before running this, of course :-) Works fine, by the way. – Drillreturn
instead ofbreak
? – Monamonachal