std::rethrow_exception
STD:重投[医]例外
Defined in header | | |
---|---|---|
[noreturn] void rethrow_exception( std::exception_ptr p ) | | (since C++11) |
抛出以前捕获的异常对象(由异常指针引用)。p
...
参数
p | - | non-null std::exception_ptr |
---|
返回值
%280%29
例
二次
#include <iostream>
#include <string>
#include <exception>
#include <stdexcept>
void handle_eptr(std::exception_ptr eptr) // passing by value is ok
{
try {
if (eptr) {
std::rethrow_exception(eptr
}
} catch(const std::exception& e) {
std::cout << "Caught exception \"" << e.what() << "\"\n";
}
}
int main()
{
std::exception_ptr eptr;
try {
std::string().at(1 // this generates an 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 destructed
二次
产出:
二次
Caught exception "basic_string::at"
二次
另见
exception_ptr (C++11) | shared pointer type for handling exception objects (typedef) |
---|---|
current_exception (C++11) | captures the current exception in a std::exception_ptr (function) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。