如何捕获boost消息队列返回false
how to catch boost message_queue returns false
我正在使用boost::interprocess::message_queue,并且根据上给出的定义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);
- 打开以前创建的名为"name"的进程共享消息队列。如果以前没有创建,或者没有可用资源,则函数将返回false
现在我不能理解的是构造函数是如何返回值的?尽管它声明"函数返回false",但afaik message_queue应该是一个构造函数。
如果它真的返回false,我能在布尔变量中捕捉到吗?
如当前文档所示,将抛出boost::interprocess::interprocess_exception
。
所以,
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";
}
运行两次时,将打印
Error: #9, File exists
相关文章:
- QueryWorkingSet总是返回false
- 当返回类型声明为 ListNode 时,我们是否可以返回 false<T>*
- 等于在 c++ 中返回 false
- strcmp 对于相等的字符序列返回 false
- C++ - 负数和正数之间的比较返回 false
- protobuf 的 ParseFromString 函数返回 false
- 递归函数始终返回 false
- 为什么 GetExitCodeThread() 在这里返回 FALSE?
- MFC 的 OnInit() 函数中的返回 true 和返回 false 有什么区别
- if 语句在条件为真时返回 false
- 为什么 std::isnan() 对于具有 NAN 值的双变量返回 false
- is_lock_free() 在升级到 MacPorts gcc 7.3 后返回 false
- 在 winapi 回调函数上返回 FALSE 时出现意外行为(循环被跳过?
- 如果数组中有重复的数字,如何返回'false'?
- std::is_array 当它应该返回 false 时返回 true
- 为什么pyarg_parsetuple总是返回false
- 删除为应该在哈希表中的记录返回 false 的函数
- Vulkan 和 glfwVulkanSupported() 总是返回 false
- tf2_ros::Buffer::canTransform() 为现有转换返回 False
- 出于某种原因,布尔值返回 false