在线文档教程
C++
应用 | Utilities

std::bad_exception

STD:不好[医]例外

Defined in header
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 virtualreturns the explanatory string (virtual public member function)

继承自STD:例外

成员函数

(destructor) virtualdestructs the exception object (virtual public member function of std::exception)
what virtualreturns an explanatory string (virtual public member function of 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

二次

© cppreference.com

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

http://en.cppreference.com/w/cpp/Error/bad[医]例外