bad_typeid Exception
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

bad_typeid Exception

The bad_typeid exception is thrown by the typeid operator when the operand for typeid is a NULL pointer.

catch (bad_typeid)

The interface for bad_typeid is:

class _CRTIMP bad_typeid : public exception {
    bad_typeid(const char * what_arg) : exception (what_arg) {}

The following example shows the typeid operator throwing a bad_typeid exception.

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

class A{
   // 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

See Also

Run-Time Type Information | C++ Keywords

© 2016 Microsoft