Sometimes you want to do something with the exception you catch (like write to log or print a warning) and let it bubble up to the upper scope to be handled. To do so, you can rethrow any exception you catch:
try {
... // some code here
} catch (const SomeException& e) {
std::cout << "caught an exception";
throw;
}
Using throw;
without arguments will re-throw the currently caught exception.
To rethrow a managed std::exception_ptr
, the C++ Standard Library has the rethrow_exception
function that can be used by including the <exception>
header in your program.