[nanomsg] Re: assertions in cpp binding

  • From: Steve Atkins <steve@xxxxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Fri, 4 Oct 2013 11:38:18 -0700

On Oct 4, 2013, at 11:10 AM, Immanuel Weber <immanuel.weber@xxxxxxxxx> wrote:

> Hi all,
> 
> I'm exploring if I can exchange the backend of our system to nanomsg and 
> started to create a Qt binding on top of the cppbinding. (If I have time, I 
> will make that available to the public...
> However the assertions, which are thrown whenever an error occurs, are a 
> little bit annoying.

It shouldn't throw assertions - if it does then you have bugs either in your 
code or in nanomsg itself.

The C++ binding will throw exceptions when there's an error.

> I mean the errors are being handled and reported to errno, so why assert 
> there? Could we get rid of them and add functionality to the socket class, to 
> check for the error which occurred and let the functions just return -1. So 
> that the user of the api can implement her/his preferred error handling?

Exceptions are the standard way of dealing with errors in C++, though Qt often 
avoids them for historical reasons.

As the c++ binding is a very thin shim that mostly just maps error returns from 
the C code into C++ exceptions you'd probably be better layering on top of the 
C code directly if you want to avoid exceptions.

You might want to add exception handling to your code instead - if you do, 
you'll probably want to inherit from QCoreApplication, add a virtual notify() 
method and put a try{} around a core to QCoreApplication::notify(), to catch 
any exceptions you've not caught closer to the point of the error.

Cheers,
  Steve

Other related posts: