目录

bad_array_new_length

描述 (Description)

这是一个异常的错误的数组长度和在以下任何情况下引发的这种类型的数组 -

  • 如果数组大小小于零。
  • 如果数组大小大于实现定义的限制。
  • 如果初始化列表中的元素数超过了要初始化的元素数。

声明 (Declaration)

以下是std :: bad_array_new_length的声明。

class bad_array_new_length;

C++11

class bad_array_new_length;

参数 (Parameters)

没有

返回值 (Return Value)

没有

异常 (Exceptions)

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

成员 (Members)

  • constructor - what_arg与成员返回的值具有相同的内容。

  • what - 用于获取字符串识别异常。

例子 (Example)

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

#include <iostream>
#include <new>
#include <climits>
int main() {
   int negative = -1;
   int small = 1;
   int large = INT_MAX;
   try {
      new int[negative];           
      new int[small]{1,2,3,4};       
      new int[large][50000000];     
   } catch(const std::bad_array_new_length &e) {
      std::cout << e.what() << '\n';
   }
}

输出应该是这样的 -

std::bad_array_new_length
↑回到顶部↑
WIKI教程 @2018