阅读量:2
C++ 标准异常类位于 头文件中,它们继承自 std::exception 类。std::exception 是一个基类,它为所有标准异常提供了一个公共的接口。以下是 C++ 标准异常类的继承关系:
class std::exception {
public:
std::exception() noexcept;
virtual ~std::exception() noexcept;
const char* what() const noexcept;
};
class std::runtime_error : public std::exception {
public:
explicit runtime_error(const std::string& message) noexcept;
const char* what() const noexcept override;
};
class std::out_of_range : public std::runtime_error {
public:
explicit out_of_range(const std::string& message) noexcept;
const char* what() const noexcept override;
};
class std::bad_alloc : public std::runtime_error {
public:
explicit bad_alloc() noexcept;
const char* what() const noexcept override;
};
class std::logic_error : public std::exception {
public:
explicit logic_error(const std::string& message) noexcept;
const char* what() const noexcept override;
};
class std::domain_error : public std::runtime_error {
public:
explicit domain_error(const std::string& message) noexcept;
const char* what() const noexcept override;
};
class std::invalid_argument : public std::runtime_error {
public:
explicit invalid_argument(const std::string& message) noexcept;
const char* what() const noexcept override;
};
class std::length_error : public std::runtime_error {
public:
explicit length_error(const std::string& message) noexcept;
const char* what() const noexcept override;
};
class std::out_of_range : public std::runtime_error {
public:
explicit out_of_range(const std::string& message) noexcept;
const char* what() const noexcept override;
};
这里列出了部分 C++ 标准异常类,它们都是从 std::exception 类继承而来的。每个异常类都有其特定的用途和构造函数,以便在程序中抛出和捕获相应的异常。
以上就是关于“C++标准异常类的继承关系”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm