std:: bad_array_new_length
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | ||||
|
(C++11)
|
||||
| Classes | ||||
|
bad_array_new_length
(C++11)
|
||||
|
(C++17)
|
||||
| Types | ||||
| Objects | ||||
|
(C++20)
|
||||
| Object access | ||||
|
(C++17)
|
|
헤더 파일에 정의됨
<new>
|
||
|
class
bad_array_new_length
:
std::
bad_alloc
|
(C++11부터) | |
std::bad_array_new_length
는 다음과 같은 경우에 유효하지 않은 배열 길이를 보고하기 위해
new-expressions
에 의해 예외로 던져지는 객체의 타입입니다:
- 배열 길이가 음수인 경우,
- 새 배열의 총 크기가 구현체 정의 최대값을 초과하는 경우,
- 이니셜라이저-절의 개수가 초기화할 요소 수를 초과하는 경우.
첫 번째 배열 차원만 이 예외를 생성할 수 있습니다; 첫 번째를 제외한 다른 차원들은 상수 표현식이며 컴파일 시간에 확인됩니다.
상속 다이어그램
목차 |
멤버 함수
|
(생성자)
|
새로운
bad_array_new_length
객체를 생성함
(public 멤버 함수) |
|
operator=
|
bad_array_new_length
객체를 대체함
(public 멤버 함수) |
|
what
|
설명 문자열을 반환함
(public 멤버 함수) |
std::bad_array_new_length:: bad_array_new_length
|
bad_array_new_length
(
)
noexcept
;
|
(1) |
(since C++11)
(constexpr since C++26) |
|
bad_array_new_length
(
const
bad_array_new_length
&
other
)
noexcept
;
|
(2) |
(since C++11)
(constexpr since C++26) |
새로운
bad_array_new_length
객체를 생성합니다. 이 객체는 구현에서 정의된 null-terminated byte string을 포함하며,
what()
함수를 통해 접근할 수 있습니다.
std::bad_array_new_length
동적 타입을 가진다면,
std::
strcmp
(
what
(
)
, other.
what
(
)
)
==
0
입니다.
매개변수
| other | - | 복사할 다른 예외 객체 |
std::bad_array_new_length:: operator=
|
bad_array_new_length
&
operator
=
(
const
bad_array_new_length
&
other
)
noexcept
;
|
(C++11부터)
(C++26부터 constexpr) |
|
내용을
other
의 내용으로 대입합니다.
*
this
와
other
모두 동적 타입
std::bad_array_new_length
를 가진다면, 대입 후
std::
strcmp
(
what
(
)
, other.
what
(
)
)
==
0
입니다.
매개변수
| other | - | 대입할 다른 예외 객체 |
반환값
* this
std::bad_array_new_length:: what
|
virtual
const
char
*
what
(
)
const
noexcept
;
|
(C++11부터)
(C++26부터 constexpr) |
|
설명 문자열을 반환합니다.
반환값
설명 정보를 담은 구현 정의 널 종료 문자열에 대한 포인터. 이 문자열은 std::wstring 으로 변환 및 표시하기에 적합합니다. 이 포인터는 적어도 해당 예외 객체가 파괴되거나 예외 객체의 비상수 멤버 함수(예: 복사 할당 연산자)가 호출되기 전까지는 유효함이 보장됩니다.
|
상수 평가 중에는 반환된 문자열이 일반 리터럴 인코딩으로 인코딩됩니다. |
(C++26부터) |
참고
구현체는
what()
을 재정의할 수 있지만 필수는 아닙니다.
std:: bad_alloc 에서 상속됨
std::exception으로부터 상속됨
멤버 함수
|
[virtual]
|
예외 객체를 파괴함
(
std::exception
의 virtual public 멤버 함수)
|
|
[virtual]
|
설명 문자열을 반환함
(
std::exception
의 virtual public 멤버 함수)
|
참고 사항
| 기능 테스트 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_constexpr_exceptions
|
202411L
|
(C++26) | constexpr 예외 타입 |
예제
std::bad_array_new_length
가 throw되어야 하는 세 가지 조건:
#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() << ": negative size\n"; } try { int small = 1; new int[small]{1,2,3}; } catch (const std::bad_array_new_length& e) { std::cout << "2) " << e.what() << ": too many initializers\n"; } try { long large = LONG_MAX; new int[large][1000]; } catch (const std::bad_array_new_length& e) { std::cout << "3) " << e.what() << ": too large\n"; } std::cout << "End\n"; }
가능한 출력:
1) std::bad_array_new_length: negative size 2) std::bad_array_new_length: too many initializers 3) std::bad_array_new_length: too large End
참고 항목
|
할당 함수
(함수) |
|
|
메모리 할당 실패 시 발생하는 예외
(클래스) |