名稱空間
變體
操作

標準庫標頭檔案 <exception>

來自 cppreference.com
 
 
標準庫標頭檔案
演算法
<algorithm>
<numeric>
字串
<cctype>
<cstring>
<cuchar> (C++11)
<cwchar>
<cwctype>
<string_view> (C++17)
<string>
文字處理
<clocale>
<codecvt> (C++11/17/26*)
<locale>
<regex> (C++11)
<text_encoding> (C++26)   
數值
<cfenv> (C++11)
<cmath>
<complex>
<linalg> (C++26)
<numbers> (C++20)
<random> (C++11)
<simd> (C++26)
<valarray>
時間
<chrono> (C++11)
<ctime>
C 相容性
<ccomplex> (C++11/17/20*)
<ciso646> (until C++20)
<cstdalign> (C++11/17/20*)
<cstdbool> (C++11/17/20*)
<ctgmath> (C++11/17/20*)
 

此標頭檔案是錯誤處理庫的一部分。

目錄

型別

標準庫元件丟擲的異常的基類
(類) [編輯]
用於捕獲和儲存當前異常的 mixin 型別
(類) [編輯]
std::current_exception 無法複製異常物件時丟擲的異常
(類) [編輯]
(C++11 中已廢棄)(C++17 中已移除)
std::unexpected 呼叫的函式型別
(型別定義) [編輯]
std::terminate 呼叫的函式型別
(型別定義) [編輯]
用於處理異常物件的共享指標型別
(型別定義) [編輯]

函式

(C++11 中已廢棄)(C++17 中已移除)
動態異常規範被違反時呼叫的函式
(函式) [編輯]
檢查當前是否正在進行異常處理
(函式) [編輯]
從異常物件建立 std::exception_ptr
(函式模板) [編輯]
將當前異常捕獲到 std::exception_ptr
(函式) [編輯]
std::exception_ptr 丟擲異常
(函式) [編輯]
丟擲其引數並混入 std::nested_exception
(函式模板) [編輯]
std::nested_exception 丟擲異常
(函式模板) [編輯]
異常處理失敗時呼叫的函式
(函式) [編輯]
獲取當前的 terminate_handler
(函式) [編輯]
更改 std::terminate 將呼叫的函式
(函式) [編輯]
(C++11 中已廢棄)(C++17 中已移除)
獲取當前的 unexpected_handler
(函式) [編輯]
(C++11 中已廢棄)(C++17 中已移除)
更改 std::unexpected 將呼叫的函式
(函式) [編輯]

[編輯] 概要

namespace std {
  class exception;
  class bad_exception;
  class nested_exception;
 
  using terminate_handler = void (*)();
  terminate_handler get_terminate() noexcept;
  terminate_handler set_terminate(terminate_handler f) noexcept;
  [[noreturn]] void terminate() noexcept;
 
  int uncaught_exceptions() noexcept;
 
  using exception_ptr = /* unspecified */;
 
  exception_ptr current_exception() noexcept;
  [[noreturn]] void rethrow_exception(exception_ptr p);
  template<class E> exception_ptr make_exception_ptr(E e) noexcept;
 
  template<class T> [[noreturn]] void throw_with_nested(T&& t);
  template<class E> void rethrow_if_nested(const E& e);
}

[編輯] std::exception

namespace std {
  class exception {
  public:
    exception() noexcept;
    exception(const exception&) noexcept;
    exception& operator=(const exception&) noexcept;
    virtual ~exception();
    virtual const char* what() const noexcept;
  };
}

[編輯] std::bad_exception

namespace std {
  class bad_exception : public exception {
  public:
    // see [exception] for the specification of the special member functions
    const char* what() const noexcept override;
  };
}

[編輯] std::nested_exception

namespace std {
  class nested_exception {
  public:
    nested_exception() noexcept;
    nested_exception(const nested_exception&) noexcept = default;
    nested_exception& operator=(const nested_exception&) noexcept = default;
    virtual ~nested_exception() = default;
 
    // access functions
    [[noreturn]] void rethrow_nested() const;
    exception_ptr nested_ptr() const noexcept;
  };
 
  template<class T> [[noreturn]] void throw_with_nested(T&& t);
  template<class E> void rethrow_if_nested(const E& e);
}

[編輯] 參閱