#9710 closed Feature Requests (wontfix)
Support std::exception_ptr in boost::promise
Reported by: | Owned by: | viboes | |
---|---|---|---|
Milestone: | To Be Determined | Component: | thread |
Version: | Boost 1.55.0 | Severity: | Problem |
Keywords: | futures | Cc: |
Description
Please add something like this to boost::promise:
void set_exception(std::exception_ptr e);
if std::exception_ptr is available.
I want to use boost futures, but don't want to wrap all of my throws in enable_current_exception(). See also: http://stackoverflow.com/questions/22010388/converting-stdexception-ptr-to-boostexception-ptr
Change History (8)
comment:1 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
follow-up: 3 comment:2 by , 9 years ago
This is a fairly annoying problem for me as well, especially when writing code where you don't have control over the exception that's thrown -- all you want to do is intercept the exception by calling std::current_exception and set the promise. I need to use boost::futures because of facilities like wait_for_any, but the fact that it implies no longer being able to capture arbitrary exceptions is a fairly annoying problem. What exactly is the issue right now that prevents adding a std::exception_ptr overload when available? It seems like in the case that std::exception_ptr is available, boost::future/promise could deal with std::exception_ptr internally instead of boost::exception_ptr, correct? Both overloads could be provided (one for std::exception_ptr and one for boost::exception_ptr) since converting boost::exception_ptr to std::exception_ptr should be a much simpler conversion than the other way around and can be done inside the implementation of boost::promise. Perhaps I'm missing some subtleties, though?
follow-up: 4 comment:3 by , 9 years ago
Maybe you are right and converting from boost::exception_ptr to std::exception_ptr could be more efficient.
Ok, I will give it a try. I will request Emil a function to do the conversion, and apply it internally. I could also do the conversion using the external interfaces waiting for an efficient version.
comment:4 by , 9 years ago
Replying to viboes:
Maybe you are right and converting from boost::exception_ptr to std::exception_ptr could be more efficient.
Ok, I will give it a try. I will request Emil a function to do the conversion, and apply it internally. I could also do the conversion using the external interfaces waiting for an efficient version.
Awesome, and thanks for such a quick reply to this!
comment:5 by , 9 years ago
Component: | threads → thread |
---|
comment:6 by , 9 years ago
Created #9769. Emil suggest to make boost::exception_ptr a typedef of std::exception_ptr when available.
comment:7 by , 8 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
I decided to don't fix this issue. #9769 should fix it.
comment:8 by , 7 years ago
MSC_VER=1600,BOOST_VER=106000 invalid catch
void foo_lang_test() { printf("MSC_VER=%d,BOOST_VER=%d\n", _MSC_VER , BOOST_VERSION ); boost::promise<void> pp; try { throw std::runtime_error("aa"); } catch(...) { pp.set_exception(std::current_exception()); } try { pp.get_future().get(); } catch(std::exception& e) { printf("catch %s\n", e.what()); } catch(...) { printf("invalid catch\n"); } }
I don't think this is possible in an efficient way. I would prefer the user do the conversion using a specific function. Maybe you should ask for this function to Boost.Exception library author.