On Tue, May 26, 2020 at 2:53 PM Bjorn Reese via Boost
On 2020-05-25 22:21, Emil Dotchevski via Boost wrote:
You mean, as in:
Good example.
leaf::result<float> f(); // Returns a float or an error
leaf::result<int> g() // Returns an int or an error { (void) f(); // Discard the float or the error returned by f return 42; }
Suppose there is also an h() function in the call stack that is being called by the error_handler() function instead of g():
leaf::result<int> h() { auto res = g(); // How to detect that f() raised an error without knowing // its error_id? return res; }
Can this function detect that someone further up the call stack has already raised an error? Similar to std::uncaught_exceptions()?
If g() still does (void) f(); (that is, discards the error), by analogy this is like try { f(); } catch(...) { }, so I don't understand why h() would care. That said, you can detect that f() reported an error. This is exposed through the augment_id API: https://zajo.github.io/leaf/#augment_id. You can instantiate this class, and then later call check_error() to see if some function (from this thread) has reported any errors since then: leaf::augment_id id; (void) f(); (void) g(); if( id.check_error() ) { // f() or g(), or something they call, reported at least one error. // The error(s) may have been discarded or handled. } Naturally, this is not common. Generally, we handle, rather than discard, all reported errors.