Difference between revisions of "cpp/memory/new/bad array new length"
From cppreference.com
m (r2.7.3) (Robot: Adding de, es, fr, it, ja, pt, ru, zh) |
m (Shorten template names. Use {{lc}} where appropriate.) |
||
Line 1: | Line 1: | ||
{{cpp/title|bad_array_new_length}} | {{cpp/title|bad_array_new_length}} | ||
{{cpp/memory/new/bad_array_new_length/navbar}} | {{cpp/memory/new/bad_array_new_length/navbar}} | ||
− | {{ | + | {{dcl begin}} |
− | {{ | + | {{dcl header | new}} |
− | {{ | + | {{dcl | notes={{mark since c++11}} | 1= |
class bad_array_new_length; | class bad_array_new_length; | ||
}} | }} | ||
− | {{ | + | {{dcl end}} |
{{tt|std::bad_array_new_length}} is the type of the object thrown as exceptions by the [[cpp/language/new|new-expressions]] to report invalid array lengths if | {{tt|std::bad_array_new_length}} is the type of the object thrown as exceptions by the [[cpp/language/new|new-expressions]] to report invalid array lengths if | ||
Line 21: | Line 21: | ||
===Member functions=== | ===Member functions=== | ||
− | {{ | + | {{dsc begin}} |
− | {{ | + | {{dsc mem ctor | cpp/memory/new/bad_array_new_length/bad_array_new_length | constructs the {{tt|bad_array_new_length}} object}} |
− | {{ | + | {{dsc end}} |
{{cpp/memory/new/bad_alloc/inherit}} | {{cpp/memory/new/bad_alloc/inherit}} | ||
Line 33: | Line 33: | ||
===Example=== | ===Example=== | ||
{{example | {{example | ||
− | | Three conditions where {{ | + | | Three conditions where {{lc|std::bad_array_new_length}} should be thrown: |
| code= | | code= | ||
#include <iostream> | #include <iostream> | ||
Line 55: | Line 55: | ||
===See also=== | ===See also=== | ||
− | {{ | + | {{dsc begin}} |
− | {{ | + | {{dsc inc | cpp/memory/new/dcl list operator_new}} |
− | {{ | + | {{dsc inc | cpp/memory/new/dcl list bad_alloc}} |
− | {{ | + | {{dsc end}} |
[[de:cpp/memory/new/bad array new length]] | [[de:cpp/memory/new/bad array new length]] |
Revision as of 19:14, 31 May 2013
Template:cpp/memory/new/bad array new length/navbar
Defined in header <new>
|
||
class bad_array_new_length; |
(since C++11) | |
std::bad_array_new_length
is the type of the object thrown as exceptions by the new-expressions 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.
Inheritance diagram
Contents |
Member functions
constructs the bad_array_new_length object (public member function) |
Inherited from std::bad_alloc
Inherited from std::exception
Member functions
[virtual] |
destroys the exception object (virtual public member function of std::exception )
|
[virtual] |
returns an explanatory string (virtual public member function of std::exception )
|
Notes
The override for the virtual member function what()
may by provided, but is not required.
Example
Three conditions where std::bad_array_new_length should be thrown:
Run this code
#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'; } }