mardi 26 mai 2015

Is it safe to use an exception outside the catch statement if it is held in a std::exception_ptr?

I have a std::exception_ptr with an exception inside it. I am going to invoke std::rethrow_exception to get the actual exception, will the exception be valid after the catch statement? My guess here is that since I still hold the std::exception_ptr it will still be valid.

See the example:

std::exception_ptr ePtr = initialize_somewhere_else();
std::runtime_error* a=NULL;
try {
    std::rethrow_exception(ePtr);
} catch(std::runtime_error& e) {
    a = &e;
}
std::cout << a << ", " << a->what() << std::endl;

Note: In my tests using Clang this does work.

Aucun commentaire:

Enregistrer un commentaire