Share via


bad_typeid uitzondering

De bad_typeid uitzondering wordt gegenereerd door de typeid-operator wanneer de operand typeid een NULL-aanwijzer is.

Syntaxis

catch (bad_typeid)
   statement

Opmerkingen

De interface voor bad_typeid is:

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

In het volgende voorbeeld ziet u de typeid operator die een bad_typeid uitzondering genereert.

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

Uitvoer

Object is NULL

Zie ook

Run-Time typegegevens
Zoekwoorden