bad_typeid 예외

피연산자가 typeid NULL 포인터인 경우 typeid 연산자에 의해 bad_typeid 예외가 throw됩니다.

구문

catch (bad_typeid)
   statement

설명

bad_typeid 인터페이스는 다음과 같습니다.

class bad_typeid : public exception
{
public:
   bad_typeid();
   bad_typeid(const char * _Message = "bad typeid");
   bad_typeid(const bad_typeid &);
   virtual ~bad_typeid();

   bad_typeid& operator=(const bad_typeid&);
   const char* what() const;
};

다음 예제에서는 bad_typeid 예외를 throw하는 연산자를 보여줍니다typeid.

// expre_bad_typeid.cpp
// compile with: /EHsc /GR
#include <typeinfo>
#include <iostream>

class A{
public:
   // object for class needs vtable
   // for RTTI
   virtual ~A();
};

using namespace std;
int main() {
A* a = NULL;

try {
   cout << typeid(*a).name() << endl;  // Error condition
   }
catch (bad_typeid){
   cout << "Object is NULL" << endl;
   }
}

출력

Object is NULL

참고 항목

런타임 형식 정보
키워드