Boost logo

Boost :

Subject: Re: [boost] LEAF has been refactored, it now has a much simplified error handling interface
From: Sorin Fetche (sorin.fetche_at_[hidden])
Date: 2019-01-22 02:13:58


On Wed, Jan 16, 2019 at 11:51 AM Emil Dotchevski via Boost
<boost_at_[hidden]> wrote:
>
> LEAF is a C++11 error handling library for use in low-latency environments.
>
> - Can be used with or without exception handling.
>

Is it possible to have a common error handling logic for both error
codes and exceptions?
Something like:

leaf::result<T> function_that_may_throw();
...
leaf::handle_all(
    [i]() -> leaf::result<int> {
        LEAF_AUTO(r, leaf::exception_to_result<std::exception>([] {
function_that_may_throw(); }));
        ...
        return 0;
    },
    [](std::exception const &e) {
        // Handle exception(s)
        return 1;
    },
    [](custom_error_code ec) {
        // Handle error code(s)
        return 2;
    })

The attached program shows that once leaf::exception_to_result() is
used, only the exceptions reach the handlers in `handle_all`.

Also, is there a way to access the "what" message of the exceptions in
the error handlers, instead of just "std::exception"?

Thanks,
Sorin





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