Cpp Exceptions

Error Throwing

Posted by Rico's Nerd Cluster on June 13, 2023

Error Throwing

rethrow an error using std::rethrow_exception(std::exception_ptr)

1
2
3
4
5
6
7
8
9
10
11
12
catch (std::exception&)
{
    exptr_ = std::current_exception();
}
if (exptr_)
{
    // The official interface of std::exception_ptr does not define any move
    // semantics. Thus, we copy and reset exptr_ manually.
    const auto exptr_copy = exptr_;
    exptr_ = nullptr;
    std::rethrow_exception(exptr_copy);
}