Boost logo

Boost :

Subject: Re: [boost] [review] Review of Outcome v2 (Fri-19-Jan to Sun-28-Jan, 2018)
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2018-01-27 03:31:55


On Thu, Jan 18, 2018 at 2:07 PM, charleyb123 . via Boost <
boost_at_[hidden]> wrote:

> Hi, Everyone,
>
> The formal review of Niall Douglas' Outcome (v2) library begins Fri-19-Jan
> and continues until Sun-28-Jan, 2018.
>

>From the Outcome documentation:

auto read_int_from_file(string_view path) noexcept
  -> outcome::result<int>
{
  OUTCOME_TRY(handle, open_file(path)); // decltype(handle) == Handle
  OUTCOME_TRY(buffer, read_data(handle)); // decltype(buffer) == Buffer
  OUTCOME_TRY(val, parse(buffer)); // decltype(val) == int
  return val;
}

Question: if using the OUTCOME_TRY macro is equivalent to calling the
function, checking for error and then returning an error if there is an
error, how is this different from using exceptions? Semantically, exception
handling does nothing more than check for errors and returning errors if
there were errors, with much more readable syntax:

return parse(read_data(open_file(path)));

This kind of macro use seems rather inelegant and more appropriate for C
programs, though it may be justified in C since it lacks exception handling.

Emil


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk