Share via


out_of_range 클래스

이 클래스는 유효 범위를 벗어난 인수를 보고하기 위해 발생하는 모든 예외에 대한 기본 클래스로 사용됩니다.

구문

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

    explicit out_of_range(const char *message);

};

설명

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

예시

// out_of_range.cpp
// compile with: /EHsc
#include <exception>
#include <iostream>
#include <string>
#include <typeinfo>
using namespace std;

int main()
{
   try
   {
      string str("Micro");
      string rstr("soft");
      str.append(rstr, 5, 3);
      cout << str << endl;
   }
   catch (const exception& e)
   {
      cerr << "Caught: " << e.what() << endl;
      cerr << "Type: " << typeid(e).name() << endl;
   }
}
/* Output:
Caught: invalid string position
Type: class std::out_of_range
*/

요구 사항

헤더:<stdexcept>

네임스페이스: std

참고 항목

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