[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/memory/new/bad_array_new_length [Back]  [Original]

std::bad_array_new_length cppreference.com
cppreference.com

std::bad_array_new_length

cppreference.com
< cpp | memory | new
 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
 
no section name
no section name
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)



no section name
 
 
<tbody> </tbody>
class bad_array_new_length;
( C++11)

std::bad_array_new_length , new ,

  1. ,
  2. , ,
  3. - .

; , , .

-

()
bad_array_new_length
(public -)
operator=
bad_array_new_length
(public -)
what

(public -)

std::bad_array_new_length::bad_array_new_length

<tbody> </tbody>
bad_array_new_length() noexcept;
(1) ( C++11)
bad_array_new_length( const bad_array_new_length& other ) noexcept;
(2) ( C++11)

bad_array_new_length , , what().

1) .
2) . *this other std::bad_array_new_length, std::strcmp(what(), other.what()) == 0.

other

std::bad_array_new_length::operator=

<tbody> </tbody>
bad_array_new_length& operator=( const bad_array_new_length& other ) noexcept;
( C++11)

other. *this other std::bad_array_new_length, std::strcmp(what(), other.what()) == 0 .

other

*this

std::bad_array_new_length::what

<tbody> </tbody>
virtual const char* what() const noexcept;
( C++11)

.

()

. std::wstring. , , , , , - (, ) .

, what().

std::exception

-

[virtual]

(virtual public of std::exception -) []
[virtual]

(virtual public of std::exception -) []

, std::bad_array_new_length :

#include <climits>
#include <iostream>
#include <new>

int main()
{
    try
    {
        int negative = -1;
        new int[negative];
    }
    catch (const std::bad_array_new_length &e)
    {
        std::cout << "1) " << e.what() << ":  \n";
    }
    
    try
    {
        int small = 1;
        new int[small]{1,2,3};
    }
    catch (const std::bad_array_new_length &e)
    {
        std::cout << "2) " << e.what() << ":   \n";
    }
    
    try
    {
        long large = LONG_MAX;
        new int[large][1000];
    } 
    catch (const std::bad_array_new_length &e)
    {
        std::cout << "3) " << e.what() << ":  \n";
    }

    std::cout << "\n";
}

:

1) std::bad_array_new_length:  
2) std::bad_array_new_length:   
3) std::bad_array_new_length:  


() []

() []

Web Proxy Viewer  |  New URL  |  Original Page