标准库标头 <exception>

来自cppreference.com
< cpp‎ | header


 
 
标准库头
通用工具
<any> (C++17)
<bitset>
<bit> (C++20)
<charconv> (C++17)
<expected> (C++23)
<format> (C++20)
<functional>
<optional> (C++17)
<stdbit.h> (C++26)
<tuple> (C++11)
<typeindex> (C++11)
<utility>
<variant> (C++17)
容器
<array> (C++11)
<deque>
<flat_map> (C++23)
<flat_set> (C++23)
<forward_list> (C++11)
<hive> (C++26)
<inplace_vector> (C++26)   
<list>
<map>
<mdspan> (C++23)
<queue>
<set>
<span> (C++20)
<stack>
<unordered_map> (C++11)
<unordered_set> (C++11)
<vector>
迭代器
<iterator>
范围
<generator> (C++23)
<ranges> (C++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 = /* 未指明 */;
 
  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:
    // 特殊成员函数的规定见 [exception]
    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;
 
    // 访问函数
    [[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);
}

[编辑] 参阅