<stdexcept>

std::logic_error

class logic_error;
邏輯錯誤異常

此類定義了用於報告程式內部邏輯錯誤的異常型別,例如違反邏輯前置條件或類不變數。

這些錯誤應該可以在程式執行前被檢測到。

它被用作幾個邏輯錯誤異常的基類,並宣告為
1
2
3
4
class logic_error : public exception {
public:
  explicit logic_error (const string& what_arg);
};
1
2
3
4
5
class logic_error : public exception {
public:
  explicit logic_error (const string& what_arg);
  explicit logic_error (const char* what_arg);
};

它的同級類 runtime_error 用於作為報告只能在執行時確定的錯誤的異常的基類。

成員

建構函式
傳遞給 what_arg 的字串與成員 what 返回的值內容相同。

此類從 exception 繼承了 what 成員函式。

異常安全

強保證: 如果建構函式丟擲異常,則沒有副作用。

另見