[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/error/rethrow_exception [Back]  [Original]

std::rethrow_exception cppreference.com
cppreference.com

std::rethrow_exception

cppreference.com
<tbody> </tbody>
[[noreturn]] void rethrow_exception( std::exception_ptr p );
( C++11)

, p, .

, . , .

, p null.

p std::exception_ptr

()

, p, .

, .

std::bad_alloc , , .

P1675R2, rethrow_exception , , .

#include <exception>
#include <iostream>
#include <stdexcept>
#include <string>

void handle_eptr(std::exception_ptr eptr) //    
{
    try
    {
        if (eptr)
            std::rethrow_exception(eptr);
    }
    catch(const std::exception& e)
    {
        std::cout << " : '" << e.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,
  //   eptr

:

 : 'basic_string::at: __n (which is 1) >= this->size() (which is 0)'


( ) []
std::exception_ptr
() []

Web Proxy Viewer  |  New URL  |  Original Page