std::length_error

std::length_error (길이 오류 예외)

객체의 최대 허용 크기를 초과하는 크기 변경을 시도했을 때 던져지는 논리 오류 예외예요. 예를 들어 std::string·std::vector가 너무 큰 크기를 요청받았을 때 발생해요.

출처: cppreference

본문

<stdexcept> 헤더에 정의돼 있고, std::logic_error에서 파생되는 예외예요.

class length_error : public logic_error;

std::length_error는 객체가 그 max_size()를 초과하는 길이로 확장되려 할 때 던져지는 예외로, std::logic_error에서 파생돼요. 예를 들어 컨테이너가 허용 가능한 최대 크기를 넘는 재할당을 요청받으면 길이 오류가 발생해요.

생성자:

  • explicit length_error( const std::string& what_arg );
  • explicit length_error( const char* what_arg );

std::vector::resize, std::string::resize/append, std::string::substr 등 크기를 다루는 표준 연산이 크기 제한을 초과하면 이 예외를 던질 수 있어요. what()은 전달한 설명 문자열을 돌려줘요.

더 알아보기 (Learn more)

cppreference