bad_typeid-Ausnahme
Die bad_typeid Ausnahme wird vom Typeid-Operator ausgelöst, wenn der Operand für typeid
einen NULL-Zeiger ist.
Syntax
catch (bad_typeid)
statement
Hinweise
Die Schnittstelle für bad_typeid lautet:
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;
};
Das folgende Beispiel zeigt den Operator, der typeid
eine bad_typeid Ausnahme auslöst.
// 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;
}
}
Ausgabe
Object is NULL
Siehe auch
Feedback
https://aka.ms/ContentUserFeedback.
Bald verfügbar: Im Laufe des Jahres 2024 werden wir GitHub-Issues stufenweise als Feedbackmechanismus für Inhalte abbauen und durch ein neues Feedbacksystem ersetzen. Weitere Informationen finden Sie unterFeedback senden und anzeigen für