Creator of ZeroMQ and AMQP comments on error handling

Jonathan M Davis jmdavisProg at gmx.com
Sun Jul 15 16:17:01 PDT 2012


On Sunday, July 15, 2012 15:26:53 José Armando García Sancio wrote:
> On Sun, Jul 15, 2012 at 3:00 PM, Tobias Pankrath <tobias at pankrath.net> 
wrote:
> >> What do you all think?
> > 
> > All his arguments about C++ exceptions hold for plain return values, too.
> 
> Yes but he would said that is not the point of his article. I think
> his point is that if you decide not to use exception in C++, for the
> reason he and others have mentioned, then C++'s classes/structs become
> nothing more than C structs with an uglier/more verbose syntax.
> 
> I am wondering if you can extend his argument to D. Implementing RIIA
> becomes more verbose. The scope keyword is useless. Thoughts?

C++ and D are designed to use exceptions. It's virtually impossible to 
completely escape them. However, because D has nothrow, you can at least 
guarantee that your code doesn't throw them (though you still have to worry 
about Errors)., even if it gets ugly in some cases like constructors, forcing 
you to do nonsense like two-part initialization, and C++ doesn't have that. D 
also has stuff like scope and  std.exception.collectException which can help 
cleanup exception-handling code quite a bit. So, D's better off than C++ is, 
even if the situation is similar.

But I tend to disagree with anyone who argues that error codes are better. 
Exceptions force you to actually deal with the errors that occur, whereas 
error codes can easily be skipped. At least some of that complication is 
intrinsic to the problem, and using error codes instead of exceptions just 
means that you're probably not handling a lot of the errors correctly.

- Jonathan M Davis


More information about the Digitalmars-d mailing list