-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Route boost::current_exception
to std::current_exception
when available?
#10
Comments
It is unclear to me who the target audience for such rerouting would be. If you use If you don't use Secondly, there are other components in Boost, e.g. |
This rerouting would only apply on C++ 11 or newer, and presumably only on compilers without borked I get the argument "why bother rerouting?". But there is also the argument "why not bother rerouting?". Unlike |
My question wasn't so much "why", but who would benefit? I understand the motivation, and I'm not against it in principle, but I am worried about possibly breaking client code which currently works fine, and I think that it is important to understand who cares about this change. The safe approach would be to provide a new configuration macro, e.g. (By the way, I am not aware of any differences between |
Actually I've realized that there is another problem: the custom error info container in While this design is not ideal and can probably be safely changed so |
This discussion stalled, was there a conclusion (for example, since it was not trivial, will we do it?) |
I don't know if this can be fixed. I'll try to explain simpler: A But that map is not thread-safe, so when a Maybe it can be done with a move constructor, but this would require I'll close this for now, if anyone has an idea for a workaround, feel free to reopen and continue the discussion. |
I have a suggestion (that would solve my use case):
This would: For reference, in my use case I need to
Does this make sense? |
Reroute to std::current_exception, how? std::exception_ptr and boost::exception_ptr are different types. |
Hum... maybe wrap the std::exception_ptr in current_exception and unwrap it in rethrow_exception? In boost::exception_detail::current_exception_impl() (around boost/exception/detail/exception_ptr.hpp:424 in boost 1.64)
In boost::rethrow_exception():
This (pseudo)code is for exposition only. Also, for simplicity this code assumes std::current_exception is available. I could provide a PR if necessary, but I doubt I can get all the #ifdef-ing right! PS: I took inspiration from https://stackoverflow.com/questions/22010388/converting-stdexception-ptr-to-boostexception-ptr/22881981 |
I'm testing the above locally and it looks like it works. Two caveats, though:
What do you think? |
Oh I see, your idea is to use This is a great idea, thank you. Since you said you've tested, I'm assuming you can send a pull request? |
I'm testing locally against Boost 1.64.0. I guess you'd like the PR against devel branch? Also, do you know which Boost preprocessor macro can I use to detect support for |
There is no config macro in Boost to detect You can send a diff with Boost 1.64.0 if that's easier. I'll review and commit manually. Thank you! |
My main compiler is VS2015, so I'm afraid |
It can't hurt to talk on the mailing list. But it may be safe to assume |
I'm working to provide a PR over develop branch. BTW, my boss gave me green light to do this task using company time, so I'll do this with my corporatey github account, just to clarify I'm not doing this in my own free time. |
About the docs, should I update the html files under doc/ directly? |
In boost::current_exception(), after all supported types of exception have been checked for, a boost::unknown_exception is stored in the boost::exception_ptr as a last resort to signal that an exception was indeed stored, but that the actual type and value of the exception was lost. Now, in case C++11 std::current_exception() is supported, the std::exception_ptr result of calling std::current_exception() is what gets stored inside the boost::exception_ptr. Later, inside boost::rethrow_exception, the std::exception_ptr is retrieved from the boost::exception_ptr and whatever exception it stores is thrown via std::rethrow_exception(). The main benefit is than now any exception thrown via plain 'throw' can be trasnported via boost::exception_ptr. Before this change it was required that the throw site either used boost::enable_current_exception() or boost::throw_exception() or threw an exception type inheriting from boost::exception, which was impossible for third party software that does not use Boost.Exception. The detection of std::current_exception() is currently done via config macro BOOST_NO_CXX11_NOEXCEPT, assuming that if 'noexcept' is supported then std::exception_ptr is also supported. A better solution would require a new dedicated macro in Boost.Config.
Added defect macro BOOST_NO_CXX11_HDR_EXCEPTION Should be #define'd when: The standard library does not provide a C++11 compatible version of <exception>. To solve Boost.Exception issue boostorg/exception#10 I need to detect compiler support for C++11 compliant: - std::exception_ptr - std::current_exception() - std::rethrow_exception()
The changes (code, tests and docs) are ready in my fork (https://github.com/dmenendez-gruposantander/exception). |
Yes, let's wait until the config change gets merged, and then I'll look at the PR. Thank you! |
Replaces: #285 Fixes #284 See also: boostorg/exception#10
Now that the Boost.Config changes have been merged to develop (thanks @jzmaddock!) I've created PR #24 with my changes, so let the code review begin! Unfortunately, some CI tests are unexpectedly failing, and I'm having a hard time deciphering the errors... Any help with this is appreciated, as I am being optimistic and was hoping to get this merged in time for the 1.72 release. |
The clang errors are because Travis switched to Xenial by default; |
Hum... This is not something I should fix in my PR, is it? |
Is there something I can do to help with this issue? |
Hi, I'm sorry to be nagging about this, but I don't see how I can get this PR merged... |
In boost::current_exception(), after all supported types of exception have been checked for, a boost::unknown_exception is stored in the boost::exception_ptr as a last resort to signal that an exception was indeed stored, but that the actual type and value of the exception was lost. Now, in case C++11 std::current_exception() is supported, the std::exception_ptr result of calling std::current_exception() is what gets stored inside the boost::exception_ptr. Later, inside boost::rethrow_exception, the std::exception_ptr is retrieved from the boost::exception_ptr and whatever exception it stores is thrown via std::rethrow_exception(). The main benefit is than now any exception thrown via plain 'throw' can be trasnported via boost::exception_ptr. Before this change it was required that the throw site either used boost::enable_current_exception() or boost::throw_exception() or threw an exception type inheriting from boost::exception, which was impossible for third party software that does not use Boost.Exception. The detection of std::current_exception() is currently done via config macro BOOST_NO_CXX11_NOEXCEPT, assuming that if 'noexcept' is supported then std::exception_ptr is also supported. A better solution would require a new dedicated macro in Boost.Config.
OK, I added However I still have problem with old versions of gcc which get confused when I bind a I tried |
At last! All tests are green! PS: the gcc problem was due to initializing the reference with braces instead of using = |
Yes, I'll look at it. Thank you! |
Any chance to get this into the 1.73 release? |
* Attempt to solve issue #10 In boost::current_exception(), after all supported types of exception have been checked for, a boost::unknown_exception is stored in the boost::exception_ptr as a last resort to signal that an exception was indeed stored, but that the actual type and value of the exception was lost. Now, in case C++11 std::current_exception() is supported, the std::exception_ptr result of calling std::current_exception() is what gets stored inside the boost::exception_ptr. Later, inside boost::rethrow_exception, the std::exception_ptr is retrieved from the boost::exception_ptr and whatever exception it stores is thrown via std::rethrow_exception(). The main benefit is than now any exception thrown via plain 'throw' can be trasnported via boost::exception_ptr. Before this change it was required that the throw site either used boost::enable_current_exception() or boost::throw_exception() or threw an exception type inheriting from boost::exception, which was impossible for third party software that does not use Boost.Exception. The detection of std::current_exception() is currently done via config macro BOOST_NO_CXX11_NOEXCEPT, assuming that if 'noexcept' is supported then std::exception_ptr is also supported. A better solution would require a new dedicated macro in Boost.Config. * Detect support for std::current_exception() via config macro BOOST_NO_CXX11_HDR_EXCEPTION The temporary solution via BOOST_NO_CXX11_NOEXCEPT was an ugly hack that is no longer necessary now that Boost.Config has BOOST_NO_CXX11_HDR_EXCEPTION (pending merge to develop). * Attempt to solve issue #10 In boost::current_exception(), after all supported types of exception have been checked for, a boost::unknown_exception is stored in the boost::exception_ptr as a last resort to signal that an exception was indeed stored, but that the actual type and value of the exception was lost. Now, in case C++11 std::current_exception() is supported, the std::exception_ptr result of calling std::current_exception() is what gets stored inside the boost::exception_ptr. Later, inside boost::rethrow_exception, the std::exception_ptr is retrieved from the boost::exception_ptr and whatever exception it stores is thrown via std::rethrow_exception(). The main benefit is than now any exception thrown via plain 'throw' can be trasnported via boost::exception_ptr. Before this change it was required that the throw site either used boost::enable_current_exception() or boost::throw_exception() or threw an exception type inheriting from boost::exception, which was impossible for third party software that does not use Boost.Exception. The detection of std::current_exception() is currently done via config macro BOOST_NO_CXX11_NOEXCEPT, assuming that if 'noexcept' is supported then std::exception_ptr is also supported. A better solution would require a new dedicated macro in Boost.Config. * Detect support for std::current_exception() via config macro BOOST_NO_CXX11_HDR_EXCEPTION The temporary solution via BOOST_NO_CXX11_NOEXCEPT was an ugly hack that is no longer necessary now that Boost.Config has BOOST_NO_CXX11_HDR_EXCEPTION (pending merge to develop). * Document detection of C++11 std::current_exception through BOOST_NO_CXX11_HDR_EXCEPTION * Added dist: trusty for Travis config, as recommended by pdimov in issue #10 * Stupid gcc 4.7 and 4.8 are confused initializing a reference with braces, using equal sign hoping it works (tested similar code on godbolt).
In my last (and first) contribution to Boost I was asked about Copyright. This is it, in case it's necessary: |
Done. |
From boostorg/system#18, suggested by @ned14:
The text was updated successfully, but these errors were encountered: