Boost logo

Boost Users :

Subject: [Boost-users] [coroutine2] - exceptions from constructor fail
From: Tamas.Ruszkai_at_[hidden]
Date: 2016-07-01 10:00:41


Hi,

I use boost 1.60 and coroutines2, Visual Studio 2015 Update 2.

When I throw an exception from the pull function after the first push, everything is ok. But if I throw an exception before the first push, then I get an Access Violation. According to the spec in this case I shall get an exception from the constructor.

In the example below:
- When I use cooperative as the pull function then I do not catch the exceptio in the mainTest side. It simply just go forward - I guess it did not rethrow the exception.
- When I use cooperative2 (I do a push before throwing the exception, then it is fine, the exception is caught in the mainTest side (as const MyError&)

What is wrong here?

Regards,
Tamas

class MyError : public std::runtime_error
{
public:
        MyError()
                : runtime_error("rt error")
        {
        }

        explicit MyError(char const* _Message)
                : runtime_error(_Message)
        {
        }


        explicit MyError(runtime_error const& _Other)
                : runtime_error(_Other)
        {
        }
};

void cooperative(boost::coroutines2::coroutine<void>::push_type &)
{
        throw MyError("error");
}

void cooperative2(boost::coroutines2::coroutine<void>::push_type &sink)
{
        sink();
        throw MyError("error");
}

void mainTest()
{
        try
        {
                #ifdef BUG
                boost::coroutines2::coroutine<void>::pull_type source(&cooperative);  // Not OK
                #else
                boost::coroutines2::coroutine<void>::pull_type source(&cooperative2); // -> OK
                source();
                #endif
        }
        catch (const MyError &e)
        {
                std::cerr << e.what() << '\n';
        }
        catch (const std::runtime_error &e)
        {
                std::cerr << e.what() << '\n';
        }
        catch (const std::exception &e)
        {
                std::cerr << e.what() << '\n';
        }
}

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