Condividi tramite


bad_typeid (eccezione)

L'eccezione bad_typeid viene generata dall'operatoretypeid quando l'operando per typeid è un puntatore NULL.

Sintassi

catch (bad_typeid)
   statement

Osservazioni:

L'interfaccia per 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;
};

Nell'esempio seguente viene illustrato l'operatore typeid che genera un'eccezione bad_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;
   }
}

Output

Object is NULL

Vedi anche

Informazioni sui tipi di runtime
Parole chiave