Compartir a través de


bad_typeid (Excepción)

La excepción bad_typeid la produce el operador typeid cuando el operando de typeid es un puntero NULL.

Sintaxis

catch (bad_typeid)
   statement

Comentarios

La interfaz para bad_typeid es:

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;
};

En el ejemplo siguiente se muestra el operador typeid que produce una excepción 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

Consulte también

Información de tipos en tiempo de ejecución
Palabras clave