Namespaces
Variants

Standard library header <exception>

From cppreference.net
Standard library headers

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

目录

类型

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

函数

(C++11 中弃用) (C++17 中移除)
当动态异常规范被违反时调用的函数
(函数)
( C++20* 中移除 ) (C++17)
检查当前是否正在进行异常处理
(函数)
从异常对象创建 std::exception_ptr
(函数模板)
std::exception_ptr 中捕获当前异常
(函数)
std::exception_ptr 抛出异常
(函数)
抛出其参数并混入 std::nested_exception
(函数模板)
std::nested_exception 抛出异常
(函数模板)
当异常处理失败时调用的函数
(函数)
获取当前的 terminate_handler
(函数)
更改由 std::terminate 调用的函数
(函数)

概要

// 所有独立环境实现
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;
  constexpr int uncaught_exceptions() noexcept;
  using exception_ptr = /* 未指定类型 */;
  constexpr exception_ptr current_exception() noexcept;
  [[noreturn]] constexpr void rethrow_exception(exception_ptr p);
  template<class E> constexpr exception_ptr make_exception_ptr(E e) noexcept;
  template<class T> [[noreturn]] constexpr void throw_with_nested(T&& t);
  template<class E> constexpr void rethrow_if_nested(const E& e);
}

std::exception

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

std::bad_exception

namespace std {
  class bad_exception : public exception
  {
  public:
    // 查看特殊成员函数规范的描述
    constexpr const char* what() const noexcept override;
  };
}

std::nested_exception

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

参见