logic_error 클래스

이 클래스는 논리적 사전 조건 위반과 같이 프로그램이 실행되기 전에 검색될 수 있는 오류를 보고하기 위해 발생하는 모든 예외에 대한 기본 클래스로 사용됩니다.

구문

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

    explicit logic_error(const char *message);

};

설명

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

예시

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

int main()
{
   try
   {
      throw logic_error("Does not compute!");
   }
   catch (const exception& e)
   {
      cerr << "Caught: " << e.what() << endl;
      cerr << "Type: " << typeid(e).name() << endl;
   }
}
/* Output:
Caught: Does not compute!
Type: class std::logic_error
*/

요구 사항

헤더:<stdexcept>

네임스페이스: std

참고 항목

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