
On Fri, Dec 16, 2016 at 2:05 PM, Andrey Semashev
On Sat, Dec 17, 2016 at 12:54 AM, Robert Ramey
wrote: On 12/16/16 12:48 PM, Emil Dotchevski wrote:
a function will either succeed or it will not return.
not necessarily
bool f() { if ... invoke_error return failure or ignore error ... return success }
if invoke error is mapped to throw exception then it will never return. If it's mapped to something else - like emitting an error message or invoking a user specified call back then it won't throw an exception.
That results in a really horrible API with dual error reporting mechanisms.
Indeed. Again, enforcing postconditions is the main benefit of throwing. Specifically: if( condition-that-code-below-cant-deal-with ) boost::throw_exception(my_error()); //safe to assume no error occurred because boost::throw_exception does nor return. The call to throw_exception is not merely reporting the error but also protecting the scope that follows. Emil