How to catch boost_queue returns false
I am using boost :: interprocess :: message_queue and as per the definition given at 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 public message queue named "name". If no resources were created earlier or there are no free resources, the function returns false.
now what i can't figure out is how the constructor returns the value? although he claims that the function returns false ", but afaik message_queue must be a constructor.
and also if it returns false, can I catch this in a boolean variable?
+3
source to share
1 answer
Instead, it will select
A boost::interprocess::interprocess_exception
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";
}
On restart it will print
Error: #9, File exists
+1
source to share