Back to Blog
std::exception_ptr
April 19, 2026
1 min read
c++
recently, I've been digging into std::exception_ptr.
i find it strange that in order to figure out what the error message is, what the type is, etc., that you have to re-throw the exception being held.
std::exception_ptr ex = faulty_func();
if (ex)
try {
std::rethrow_exception(ex);
}
catch (const std::exception& ex) {
std::println("Here's what went wrong: {}", ex.what());
}
catch (...) {
std::println("We're not quite sure what went wrong here");
}
it seems like there should be a way to introspect on the exception that it's pointing to because, i mean, doesn't it have the address of the exception?
i'm going to look into this, and maybe i'll come up with a better version of std::exception_ptr.