bad_typeid 例外狀況
當 的運算元 typeid
是 Null 指標時, typeid 運算子 會擲回bad_typeid 例外狀況。
語法
catch (bad_typeid)
statement
備註
bad_typeid 的 介面為:
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;
};
下列範例顯示 typeid
擲 回bad_typeid例外狀況 的運算子。
// 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;
}
}
輸出
Object is NULL
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應