But of course the two approaches use completely different strategies. In one case the programmer has to write if( error ) return error, like a neanderthal. In the other, he has to write exception-safe code but the upside is less error handling bugs, which is important as error handling code is notoriously difficult to test. <deleted> I would therefore not draw as thick a line between the two approaches as some here are doing. For systems programming where you are a thin veneer around OS calls a 98% result based noexcept programming style is the optimal way of doing this sort of C++ programming - tiny runtime overhead, powerful abstraction over C error code programming, highly maintainable and extremely amenable to static analysis to catch logic errors.
Lots of adjectives, perhaps we should discuss each one of them? :)
The use of error codes in low level APIs is a fact of life, since most of that code is written in C anyway. I wouldn't call it optimal in C++, I personally convert error codes into exceptions at the earliest possible opportunity. As for runtime overhead, like I said already, where it matters it can be easily deleted, by inlining; and, in such contexts you need to inline with or without exception handling: I've never seen a case where I could afford the overhead of a function call but could not afford the exception handling overhead in the same function.
It feels strange to have to defend the use of exceptions for reporting errors in C++, on the boost development board of all places. There are many other advantages, for example when returning errors there is no such thing as error-neutral contexts in your program, which increases coupling. Yes, in some contexts one can't afford to use exceptions, but all general complains that exception handling causes performance or any other problems are theoretical, at best.
I couldn't agree more. It is questionable at best to base design decisions on the pseudo argument of 'exceptions incur too much overhead'. In my experience, the benefits of using exceptions clearly outweighs any disadvantages. Regards Hartmut --------------- http://boost-spirit.com http://stellar.cct.lsu.edu