std::exception_ptr and catching and re-throwing exceptions
I want to write a bit of code that catches all exceptions thrown from a third-party function, takes a look at the exception message, and re-throws the exception later. I have written it like this: std::string message = Foo(); std::exception_ptr eptr = nullptr; try { ThirdPartyMayThrow(); } catch (...) { // (1) eptr = std::current_exception(); try { throw; } catch (const std::exception &e) { (message += ": ") += e.what(); // append what } catch (...) { // (2) } } SendMessage(message); if (eptr) { std::rethrow_exception(eptr); } I want all exceptions from ThirdPartyMayThrow() to be caught before
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.