Suppose I have an std::exception_ptr instance. I need to check if underlying exception is of certain type (and ideally get access to it). It can be done this way:
std::exception_ptr p = ...;
try
{
std::rethrow_exception(p);
}
catch(MyType const& x)
{
...
}
catch(...)
{
// do smth else
}
Is there a better way?
Is there a guarantee std::rethrow_exception isn't going to copy underlying exception leading to problems like throwing std::bad_alloc instead?
Aucun commentaire:
Enregistrer un commentaire