Boost logo

Boost Users :

Subject: [Boost-users] [Exception] Expected<T> C++03
From: Szymon Gatner (szymon.gatner_at_[hidden])
Date: 2012-12-12 10:14:53


Hi,

I trying to implement Andrei's Expected<T> from his "Systematic Error
Handling in C++" talk
(
http://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Andrei-Alexandrescu-Systematic-Error-Handling-in-C)
in C++03 / BOOST

In short: Expected<T> holds either T or exception_ptr holding exception
that prevented T's creation. Think of single threaded future<T>.

One of main purposes of this type is efficiency - code that computes T
would normally throw in case of errors but instead it returns exception by
value which causes Expected<T> to be initiated with exception type instead
of actual value of T. Important part is that no throwing happens in library
code (making it fast).

As with future<T> throwing of stored exception only happens upon client's
request - a call to get() in case of invalid computation
(Expected<T>::valid() may be called beforehand to check if
computation succeeded).

To the point: Andrei's code uses std::make_exception_ptr() which I assume
is std version of boost::copy_exception(). Now problem with
copy_exception() is that it actually throws! So the whole idea of not
throwing is gone by the fact that I don't know how to transform (const
Exception&) into boost::exception_ptr (without throwing via
copy_exception()).

How does std::make_exception_ptr() work (as I assume it does not throw &
return current_exception() as boost::copy_exception does)? Any suggestions
welcome.

Cheers.
Szymon Gatner



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net