Why have a nothrow_integer type at all?

Exceptions are standard C++, but there are a number of people that dislike them intensely and won't use any library that forces its users to deal with them. That is not the primary motivation for the nothrow_integer type though.

There are also times when exception-handling can get in the way of writing code that is easily understandable by other people. Any software developer understands calling a function and checking the return value to see if there was an error; it's a standard idiom in essentially any programming language, and it's even widely used in the C++ Standard Template Library (see std::string::find, for just one example).

Writing code that is human-readable -- not just machine-readable -- is difficult, and there's little that anyone can do to change that. But giving the developer the choice to use either exceptions or error codes, depending on which is most readable, makes it easier to produce such code, and costs nothing to the people who choose not to use it.


© Copyright Chad Nelson, 2010-2011. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)