std::current_exception是C++11引入的一个函数,定义在<exception>头文件中。它的作用是捕获当前正在处理的异常,并返回一个指向该异常的std::exception_ptr智能指针。如果当前没有正在处理的异常,则返回一个空指针。描述std::current_exception的用法: std::current_exception通常在catch子句中调用,用于捕获当前...
#include <exception> int main() { try { throw gcnew System::Exception("Managed exception"); } catch (...) { std::exception_ptr ex = std::current_exception(); try { std::rethrow_exception(ex); } catch (std::bad_exception const &) { // 会打印此行。 std::cout << "Bad ...
以下代码中对std::current_exception的调用是否应该返回一个非空exception_ptr?在我们尝试过的大多数其他...
第二步放到B线程,就能解决std::thread 潜在的两次拷贝和对象(Windows的窗口对象等)绑定到线程问题,就...
what() << "\"\n"; } } int main() { std::exception_ptr eptr; try { std::string().at(1); // 这生成一个 std::out_of_range } catch(...) { eptr = std::current_exception(); // 捕获 } handle_eptr(eptr); } // std::out_of_range 的析构函数调用于此,在 ept 析构时 ...
我想这std :: current_exception()将使用某种类似的方式来访问异常,制作异常的副本,并实例化一个std :: exception_ptr可以稍后重新抛出的适当的异常。那么我错过了什么吗?我尝试了一些微不足道的事情catch(auto x),但它似乎没有完成这项工作。yur*_*hek 2 之前std::exception_ptr曾boost::exception_ptr尝试在...
()<<"'\n";}}intmain(){std::exception_ptreptr;try{[[maybe_unused]]charch=std::string().at(1);// this generates a std::out_of_range}catch(...){eptr=std::current_exception();// capture}handle_eptr(eptr);}// destructor for std::out_of_range called here, when the eptr is ...