命名空间
变体
操作

标准库头文件 <exception>

来自 cppreference.cn
< cpp‎ | header
 
 
标准库头文件
算法
<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*)
 

此头文件是 错误处理 库的一部分。

目录

类型

标准库组件抛出的异常的基类
(类) [编辑]
一种用于捕获和存储当前异常的混入类型
(类) [编辑]
std::current_exception 无法复制异常对象时抛出的异常
(类) [编辑]
(C++11 中已弃用)(C++17 中移除)
std::unexpected 调用的函数的类型
(typedef) [编辑]
std::terminate 调用的函数的类型
(typedef) [编辑]
用于处理异常对象的共享指针类型
(typedef) [编辑]

函数

(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);
}

[编辑] 参见