C++ 異常庫 - bad_typeid



描述

此異常在空指標的 typeid 上丟擲。

宣告

以下是 std::bad_typeid 的宣告。

class bad_typeid;

C++11

class bad_typeid;

引數

返回值

異常

無丟擲保證 - 沒有成員丟擲異常。

示例

以下示例演示了 std::bad_typeid 的用法。

#include <iostream>
#include <typeinfo>
 
struct S { 
   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';
   }
}

示例輸出應如下所示:

std::bad_typeid
exception.htm
廣告