目录

bad_alloc

描述 (Description)

这是在分配内存失败时抛出的异常。

声明 (Declaration)

以下是std :: bad_alloc的声明。

class bad_alloc;

C++11

class bad_alloc;

参数 (Parameters)

没有

返回值 (Return Value)

没有

异常 (Exceptions)

No-throw guarantee - 没有成员抛出异常。

例子 (Example)

在下面的示例中为std :: bad_alloc。

#include <iostream>
#include <new>
int main () {
   try {
      int* myarray= new int[500000];
   } catch (std::bad_alloc& ba) {
      std::cerr << "bad_alloc caught: " << ba.what() << '\n';
   }
   return 0;
}
↑回到顶部↑
WIKI教程 @2018