Change KeepAlive lease expiry to throw std::out_of_range (#55)

Update documentation to show different exceptions used by KeepAlive as well.
This commit is contained in:
Nils Carlson 2021-04-08 02:18:26 +00:00 committed by GitHub
parent 3e30c4c61d
commit ad2da0ac7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -540,8 +540,10 @@ is constructed.
if (eptr) {
std::rethrow_exception(eptr);
}
} catch(const std::exception& e) {
std::cerr << "Caught exception \"" << e.what() << "\"\n";
} catch(const std::runtime_error& e) {
std::cerr << "Connection failure \"" << e.what() << "\"\n";
} catch(const std::out_of_range& e) {
std::cerr << "Lease expiry \"" << e.what() << "\"\n";
}
};
etcd::KeepAlive keepalive(etcd, handler, ttl, lease_id);

View File

@ -158,8 +158,8 @@ void etcd::KeepAlive::refresh()
throw std::runtime_error("Failed to refresh lease: error code: " + std::to_string(resp.error_code()) +
", message: " + resp.error_message());
}
if (resp.value().ttl() == -1) {
throw std::runtime_error("Failed to refresh lease due to expiration: the new TTL is -1.");
if (resp.value().ttl() == 0) {
throw std::out_of_range("Failed to refresh lease due to expiration: the new TTL is 0.");
}
// trigger the next round;
this->refresh();