Closed noisypants closed 3 years ago
cti::recover
and cti::rethrow
are fully supported to change the current error state as described in the documentation. Those functions return a cti::result
which can be returned from any handler to change the current error state, either recover from it or introduce an exceptional result:
http_request("example.com")
.then([](std::string content) -> cti::result<int, int> {
return recover(1, 2);
})
.fail([](cti::exception_t exception) -> cti::result<int, int> {
return recover(1, 2);
})
.then([](int a, int b) -> cti::result<int, int> {
// Recovered from the failure
})
http_request("example.com")
.then([](std::string content) {
return rethrow(std::make_exception_ptr(std::exception{}));
})
.fail([](cti::exception_t exception) {
return rethrow(std::make_exception_ptr(std::exception{}));
})
.next([](auto&&...) {
return rethrow(std::make_exception_ptr(std::exception{}));
});
awesome! thanks. I missed that in the docs. I will give that a shot.
@Naios Hello. Nice work with this library. it's been fun integrating it into our traditional callback flows.
I am wondering if there's any support to continue-on-fail? Something similar to
recover
in Scala futures? Basically handling an exception and allowing the chain to continue with a value or re-throwing the exception for the nextfail
handler to be triggered? I have use-cases where this is very handy.https://www.scala-lang.org/api/2.12.3/scala/concurrent/Future.html#recover
thanks.