bad_typeid


class
<typeinfo>
class bad_typeid;

Exception thrown on typeid of null pointer

bad_typeid


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
19
// bad_typeid example
#include <iostream>
#include <typeinfo>
using namespace std;

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

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


Possible output:

bad_typeid caught: St10bad_typeid


See also