You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The first overload takes a boost::exception_ptr (note: notstd::exception_ptr) wrapping a concrete exception. The second overload accepts a concrete exception object itself (and internally wraps it in boost::exception_ptr).
When set_exception() is called with an argument of type std::exception_ptr, the second overload is matched, so boost::promise treats std::exception_ptr as the concrete exception type.
The reason this is a problem (besides the inefficiency of wrapping an exception in two layers of exception pointers), is that when the other side (future::get()) throws the exception, the thrown exception object will be the std::exception_ptr itself, not the concrete exception object that it wraps.
For example, suppose the concrete exception type is boost::system::system_error (as is the case in http_async_connection::handle_received_data()). While the client code may be expecting to catch it with a catch clause like this:
catch (boost::system::system_error& e) {
...
}
in fact this catch clause will not be matched, because the thrown type was std::exception_ptr.
The fix is simple: when calling boost::promise::set_exception(), don't wrap the concrete exception type with std::make_exception_ptr: just pass the concrete exception object directly.
Activity
deanberris commentedon Feb 11, 2018
Wow, good catch @HighCommander4 -- do you mind sending a PR to fix these mis-uses of the API? I'd really appreciate it!
HighCommander4 commentedon Feb 11, 2018
I can try as soon as I figure out how to build the master branch (currently running into #816).
Do not wrap exceptions passed to boost::promise::set_exception in std…
Do not wrap exceptions passed to boost::promise::set_exception in std…