length_error 클래스

이 클래스는 너무 길어서 지정할 수 없는 개체 생성 시도를 보고하기 위해 발생하는 모든 예외에 대한 기본 클래스로 사용됩니다.

구문

class length_error : public logic_error {
public:
    explicit length_error(const string& message);

    explicit length_error(const char *message);

};

설명

반환되는 what() 값은 .의 message.data()복사본입니다. 자세한 내용은 whatdata를 참조하세요.

예시

// length_error.cpp
// compile with: /EHsc
#include <cstddef>
#include <exception>
#include <iostream>
#include <typeinfo>
#include <vector>
using namespace std;

int main()
{
   try
   {
      vector<int> v(100 + static_cast<size_t>(-1) / sizeof(int));
   }
   catch (const exception& e)
   {
      cerr << "Caught: " << e.what() << endl;
      cerr << "Type: " << typeid(e).name() << endl;
   }
}
/* Output:
Caught: vector too long
Type: class std::length_error
*/

요구 사항

헤더:<stdexcept>

네임스페이스: std

참고 항목

logic_error 클래스
C++ 표준 라이브러리의 스레드 보안