bad_typeid exception
The bad_typeid exception is thrown by the typeid operator when the operand for typeid
is a NULL pointer.
Syntax
catch (bad_typeid)
statement
Remarks
The interface for 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;
};
The following example shows the typeid
operator throwing a bad_typeid exception.
// 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;
}
}
Output
Object is NULL
See also
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for