std::bad_exception

定义于头文件 <exception>
class bad_exception;

std::bad_exception 是 C++ 运行时在下列情况抛出的异常类型:

1)std::exception_ptr 存储被捕捉异常的副本,且被 std::current_exception 捕捉的异常对象的复制构造函数抛出异常,则被捕捉的异常是 std::bad_exception 的一个实例。
2)动态异常规定被违背且 std::unexpected 抛出或重抛仍然违背异常规定的异常,但异常规定允许 std::bad_exception ,则抛出 std::bad_exception
(C++17 前)
cpp/error/exceptionstd-bad exception-inheritance.svg
关于这幅图像

继承图

目录

成员函数

构造 bad_exception 对象
(公开成员函数)
复制该对象
(公开成员函数)
[虚]
返回解释性字符串
(虚公开成员函数)

继承自 std::exception

成员函数

析构该异常对象
(std::exception 的虚公开成员函数)
[虚]
返回解释性字符串
(std::exception 的虚公开成员函数)

示例

#include <iostream>
#include <exception>
#include <stdexcept>
 
void my_unexp() { throw; }
 
void test() throw(std::bad_exception)
{
    throw std::runtime_error("test");
}
 
int main()
{
    std::set_unexpected(my_unexp);
    try {
         test();
    } catch(const std::bad_exception& e)
    {
        std::cerr << "Caught " << e.what() << '\n';
    }
}

输出:

Caught std::bad_exception

版本历史

  • (当前 | 先前 2017年5月18日 (四) 03:25Fruderica讨论 | 贡献. . (1,580字节) (-920). . (撤销)
  • 当前 | 先前 2014年10月26日 (日) 17:44P12bot讨论 | 贡献 . . (2,500字节) (0). . (Fix some translations) (撤销)
  • 当前 | 先前 2013年7月2日 (二) 09:01P12bot讨论 | 贡献 . . (2,500字节) (-50). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 16:58P12bot讨论 | 贡献 . . (2,550字节) (+249). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 11:35P12讨论 | 贡献 . . (2,301字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 07:00TranslationBot讨论 | 贡献. . (2,301字节) (-56). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 14:24P12讨论 | 贡献 . . (2,357字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 13:00TranslationBot讨论 | 贡献. . (2,357字节) (+2,357). . (Translated from the English version using Google Translate)