[Boost.Exception] A couple of unspotted areas

Hi,
I'm trying to use Boost.Exception library and I have some issues here.
1. How to build exception hierarchy correctly?
According to examples I wrote:
#include <iostream>
#include

On 19/07/2012 10:56 a.m., Alexander Mingalev wrote:
catch (const std::exception& e) { throw boost::enable_error_info(e) << Tag1(1); }
I believe that should be catch(boost::exception& e) { e << Tag1(1); throw; // rethrow original exception } so to preserve the original exception being thrown. You are currently throwing a new exception copied from std::exception e. Agustín K-ballo Bergé.- http://fusionfenix.com

On Thu, Jul 19, 2012 at 6:56 AM, Alexander Mingalev
1. How to build exception hierarchy correctly?
According to examples I wrote:
#include <iostream> #include
struct Error1 : virtual public std::exception, virtual public boost::exception { Error1(const char* msg) : std::exception(msg) {} };
struct Error2 : virtual public Error1 { Error2(const char* msg) : Error1(msg) {} };
...
std::cout << Error2("zzz").what() << std::endl;
I'd recommend leaving the std::what() alone. Define the exception type hierarchy as simple empty structs: struct base_exception: virtual std::exception, virtual boost::exception { }; struct error1: virtual base_exception { }; struct error2: virtual error1 { }; struct error3: virtual error1, virtual error2 { }; Regardless of their type, exception objects can carry any number of boost::error_info objects.
2. Strange behavior of boost::enable_error_info <snipped>
Where is Tag2 data?
Look at Augustín's answer. I'd also recommend to not bother with enable_error_info, just call BOOST_THROW_EXCEPTION to throw objects of "empty" types arranged in a hierarchy deriving from boost::exception. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
participants (3)
-
Agustín K-ballo Bergé
-
Alexander Mingalev
-
Emil Dotchevski