3

I am using boost::interprocess::message_queue and as per the definition given on http://www.boost.org/doc/libs/1_35_0/doc/html/boost/interprocess/message_queue.html

message_queue(open_only_t open_only, const char * name);
  • Opens a previously created process shared message queue with name "name". If the was not previously created or there are no free resources, the function returns false.

now what i can't understand is that how a constructor is returning a value? though it states " the function returns false" but afaik message_queue is supposed to be a constructor.

and also if it do return false can i catch that in a Boolean variable?

2
  • 1
    That's an error in the documentation, a constructor can't return anything. Commented Oct 12, 2014 at 11:59
  • 1
    boost.org/doc/libs/1_56_0/doc/html/boost/interprocess/… <- current version of the docs Commented Oct 12, 2014 at 12:01

1 Answer 1

1

A boost::interprocess::interprocess_exception will be thrown instead, as the current documentation suggests.

So,

using namespace boost::interprocess;
try {
    //Create a message_queue. If the queue
    //exists throws an exception
    message_queue mq
        (create_only         //only create
         ,"message_queue"     //name
         ,100                 //max message number
         ,100                 //max message size
        );
} catch (interprocess_exception const& ipe)
{
    std::cerr << "Error: #" << ipe.get_error_code() << ", " << ipe.what() << "\n";
}

When run twice, will print

Error: #9, File exists
Sign up to request clarification or add additional context in comments.

1 Comment

yeah.. i am doing the same now, but unfortunately i was referencing to old documentation which seems to say that constructor "returned false", that's what was troubling me. Thanks for the answer anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.