[zeromq-dev] Questions about Coding Style
Pieter Hintjens
ph at imatix.com
Sat Feb 11 20:13:14 CET 2012
On Sat, Feb 11, 2012 at 6:27 PM, niXman <i.nixman at gmail.com> wrote:
> For example the call:
>>rc = zmq_setsockopt (sub, ZMQ_SUBSCRIBE, 0, 4);
> will end on segmentation fault on line 56 of the sub.cpp file.
>
> According to the documentation, if an error occurs, the function
> should return -1.
>
> I can not decide how to handle such a situation. Should I use assert
> or return EINVAL?
Assertions were historically misused in ZeroMQ to handle user errors.
They should be used only to assert impossible conditions, i.e.
internal errors where continuing is unacceptable. It is (I've used
this analogy before) like a cell being highly resistant to invading
bacteria and viruses, but self-destructing it if gets a mutation in
its DNA.
Any remaining cases of asserting on bad input are considered bugs, and
can be fixed as such (issue, test case, and patch).
Thanks a lot for the code review, this is great.
-Pieter
More information about the zeromq-dev
mailing list