#include <iostream>
int main(void)
{
char* p = nullptr;
p = new char[0x7fffffff]; // 不捕捉异常
p = new (std::nothrow) char[0x7fffffff];
if (p == nullptr) {
std::cout << "memory not enough" << std::endl;
}
try {
p = new char[0x7fffffff];
}
catch (std::bad_alloc e) {
std::cout << "memory not enough" << std::endl;
}
try {
p = new char[0x7fffffff];
}
catch (...) {
std::cout << "memory not enough" << std::endl;
}
system("pause");
return 0;
}
不捕捉异常: