如何使用 JZMQ 处理错误?

How to handle errors with JZMQ?

documentation for Socket#recv() 内容为:

Returns: [...] null on error.

我怎么知道错误是什么?我想专门处理EAGAIN

我在这里的知识非常有限,但从它的外观来看,答案可能是:
"If Socket#recv() returns null and no ZMQException was thrown, an EAGAIN error occurred."

我跟随方法调用并在 Socket.cpp 中到达了 do_readline 83 上变得有趣的地方:

rc = zmq_recv (socket, message, flags);
int err = zmq_errno();
if (rc < 0 && err == EAGAIN) {
    rc = zmq_msg_close (message);
    err = zmq_errno();
    if (rc != 0) {
        raise_exception (env, err);
        return NULL;
    }
    return NULL;
}
if (rc < 0) {
    raise_exception (env, err);
    rc = zmq_msg_close (message);
    err = zmq_errno();
    if (rc != 0) {
        raise_exception (env, err);
        return NULL;
    }
    return NULL;
}
return message;

我在这里读到的是,如果出现问题,您会在 Java 中得到一个 ZMQException 除非错误是 EAGAINzmq_msg_close 不会出错 (我不确定 zmq_msg_close 做了什么,但我认为它很少出错)。
但是我没有测试这个的环境,我也不是很懂 raise_exception 的工作原理(来源 util.cpp): 如果两个异常是 raised/thrown 在同一个 code-path 中(例如,当 err 不是 EAGAIN 和 rc < 0 时)并且你只能在 Java?

附带说明,在中添加了对 EAGAIN 错误代码的支持 this commit 2015 年 5 月 15 日。

源代码是:

    /**
         * Receive a message.
         *
         * @return the message received, as an array of bytes; null on error.
         */ 
        public final byte[] recv()
        {
            return recv(0);
        }

        /**
         * Receive a message.
         *
         * @param flags
         *            the flags to apply to the receive operation.
         * @return the message received, as an array of bytes; null on error.
         */
        public final byte[] recv(int flags)
        {
            zmq.Msg msg = base.recv(flags);

            if (msg != null) {
                return msg.data();
            }

            mayRaise();
            return null;
        }

        private void mayRaise()
        {
            int errno = base.errno();
            if (errno != 0 && errno != zmq.ZError.EAGAIN) {
                throw new ZMQException(errno);
            }
        } 

因此您可以更改 recv(int flags) 和 mayRaise() 函数