std::bad_typeid
From Cppreference
Defined in header <typeinfo>
|
||
class bad_typeid : public std::exception;
|
||
An exception of this type is thrown when a typeid operator is applied to a dereferenced null pointer value or a polymorphic type.
Contents |
[edit] Member functions
|
constructs a new bad_typeid object (public member function) |
||
|
copies a bad_typeid object (public member function) |
||
|
returns explanatory string (virtual public member function) |
Inherited from std::exception
Member functions
|
destructs the exception object (virtual public member function) |
||
|
returns explanatory string (virtual public member function) |
[edit] Example
#include <iostream> #include <typeinfo> struct S { // The type has to be polymorphic virtual void f(); }; int main() { S* p = nullptr; try { std::cout << typeid(*p).name() << '\n'; } catch(const std::bad_typeid& e) { std::cout << e.what() << '\n'; } }
Output:
Attempted a typeid of NULL pointer!