std::bad_array_new_length

来自cppreference.com
< cpp‎ | memory‎ | new

 
 
 
 
 
std::bad_array_new_length
成员函数
原文:
Member functions
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。
继承自 std::exception
 
定义于头文件 <new>
class bad_array_new_length;
(C++11 起)

std::bad_array_new_length is the type of the object thrown as exceptions by the 新的表达式 to report invalid array lengths if

1) array length is negative

2) total size of the new array would exceed implementation-defined maximum value

3) the number of initializer-clauses exceeds the number of elements to initialize

Only the first array dimension may generate this exception; dimensions other than the first are constant expressions and are checked at compile time.

cpp/error/exceptioncpp/memory/new/bad allocstd-bad array new length-inheritance.svg
关于这幅图像

继承图

目录

[编辑] 成员函数

构建bad_array_new_length对象
原文:
constructs the bad_array_new_length object
文本通过谷歌翻译机器翻译。
你可以帮忙校正和验证翻译。点击此处查看指示。

(公开成员函数)

继承自 std::bad_alloc

继承自 std::exception

成员函数

析构该异常对象
(std::exception 的虚公开成员函数) [编辑]
[虚]
返回解释性字符串
(std::exception 的虚公开成员函数) [编辑]

[编辑] 注释

The override for the virtual member function what() may by provided, but is not required.

[编辑] 示例

Three conditions where std::bad_array_new_length should be thrown:

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


[编辑] 另请参阅

分配函数
(函数) [编辑]
内存分配失败时抛出的异常
(类) [编辑]