class
<typeinfo>

std::bad_typeid

class bad_typeid;
Exception thrown on typeid of null pointer

Type of the exceptions thrown by typeid when applied on a pointer to a polymorphic type which has a null pointer value.

Its member what returns a null-terminated character sequence identifying the exception.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// bad_typeid example
#include <iostream>       // std::cout
#include <typeinfo>       // operator typeid, std::bad_typeid

class Polymorphic {virtual void Member(){}};

int main () {
  try
  {
    Polymorphic * pb = 0;
	std::cout << typeid(*pb).name();
  }
  catch (std::bad_typeid& bt)
  {
    std::cerr << "bad_typeid caught: " << bt.what() << '\n';
  }
  return 0;
}


Possible output:

bad_typeid caught: St10bad_typeid

Exception safety

No-throw guarantee: no members throw exceptions.

See also