Boost logo

Boost Users :

Subject: [Boost-users] [Boost.Exception] A couple of unspotted areas
From: Alexander Mingalev (infest21h_at_[hidden])
Date: 2012-07-19 09:56:43


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 <boost/exception/all.hpp>

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've got
"Unknown exception" instead of "zzz"

2. Strange behavior of boost::enable_error_info

Look at this example:

#include <iostream>
#include <boost/exception/all.hpp>

typedef boost::error_info<struct Tag1_, int> Tag1;
typedef boost::error_info<struct Tag2_, int> Tag2;

void f1();
void f2();

int main()
{
        try
        {
                f1();
        }
        catch (const std::exception& e)
        {
                std::cout << boost::diagnostic_information(e) << std::endl;
        }

        return 0;
}

void f1()
{
        try
        {
                f2();
        }
        catch (const std::exception& e)
        {
                throw boost::enable_error_info(e) << Tag1(1);
        }
}

void f2()
{
        throw boost::enable_error_info(std::runtime_error("f2 exception"))
                << Tag2(2)
                ;
}

It prints:

Throw location unknown (consider using BOOST_THROW_EXCEPTION)
Dynamic exception type:
boost::exception_detail::error_info_injector<std::exception>
std::exception::what: std::exception
[Tag1_*] = 1

Where is Tag2 data?
Looks like enable_error_info erases all previous accumulated infos.
Besides, type of exception is reported as "std::exception", not
"std::runtime_error"




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