首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::bad_exception

Defined in header <exception>

class bad_exception;

std::bad_exception是C++运行时在以下情况下引发的异常的类型:

1%29std::exception_ptr存储捕获异常的副本,如果异常对象的副本构造函数被std::current_exception引发异常,则捕获的异常是std::bad_exception...

2) If a dynamic exception specification is violated and std::unexpected throws or rethrows an exception that still violates the exception specification, but the exception specification allows std::bad_exception, std::bad_exception is thrown.

(until C++17)

二次

二次

继承图

成员函数

(constructor)

constructs the bad_exception object (public member function)

operator=

copies the object (public member function)

what virtual

returns the explanatory string (virtual public member function)

继承自STD:例外

成员函数

(destructor) virtual

destructs the exception object (virtual public member function of std::exception)

what virtual

returns an explanatory string (virtual public member function of std::exception)

二次

代码语言:javascript
复制
#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';
    }
}

二次

产出:

二次

代码语言:javascript
复制
Caught std::bad_exception

二次

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券