
Steven Watanabe wrote:
AMDG
On 06/23/2012 04:19 PM, Robert Ramey wrote:
or if you want to add your own sauce
catch(std::exception &e){ std::exception_ptr e = std::current_exception(); someclass se(e, extra stuff); // home brew or from some library std::throw(se); }
or if you want to catch anyone's stuff
catch(...){ std::exception_ptr e = std::current_exception(); my_unknown_exception me(e); // though its not clear what the upper level could do with this }
this would confine the usage of boost exception to areas where the user can decide whether or not he want's to use it. It looks to me that the standard was conceived to support just this usage.
I disagree. std::exception_ptr was primarily designed to allow exceptions to be passed between threads. The interface doesn't allow you to do much besides rethrowing it unchanged. Doing this means that the caller has to catch someclass or my_unknown_exception instead of boost::archive_exception. It's true that using exception_ptr preserves all the information from the original exception, but it doesn't do it in a very convenient or accessible way.
hmmm - how do you believe that those who wrote the standard envisioned that this would be caught an handled?
Even worse, if you use this in pre-existing code, you've just introduced a breaking change, because the type of the exception that comes out is different.
I'm not seeing this. If I throw a member of the class archive_exception, trap it in the above and rethrow it. Cannot I can catch it the same way I did here?
I don't see why that would be the case. The point of using Boost.Exception is to be able to add context information to any exception as it goes by, not to do any real error handling.
I did this with "someclass" above. presumable the mechanics of "someclass" would be some part of boost exception. Then sometime higher one would catch someclass. since someclass copies the pointer there would be no slicing. This would be pretty much the same as boost exception as I understand it but not require any special code at the throw site.
How is this different from using std::exception ? You can't add your own stuff to a live std::exception. I believe equivalent functionality is available. I believe that boost exception is more intrusive that it has to be.
Boost.Exception helps keep the exception hierarchy clean.
a) The type of the exception indicates the actual error that occurred and contains any information specific to the error.
b) boost::exception contains various information about the context of the exception.
Your latest solution mixes (a) and (b) in a way that makes (a) difficult to get at.
The only substantive difference in functionality between the above and boost exception is that boost exceptiion requires creation of a wrapper at the throw site. I believe that boost exception functionality could be implemented without requiring this. This would be a far better and more robust solution and be much more useful when incorporating exisiting applications. Robert Ramey