Return true if the retry loop should continue afterstatus.
This functions are typically used in a retry loop, where they control whether to continue, whether a failure should be retried, and finally how to format the error message.
std::unique_ptr<RetryPolicy> policy = ....;
Status status;
while (!policy->IsExhausted()) {
auto response = try_rpc(); // typically `response` is StatusOr<T>
if (response.ok()) return response;
status = std::move(response).status();
if (!policy->OnFailure(response->status())) {
if (policy->IsPermanentFailure(response->status()) {
return StatusModifiedToSayPermanentFailureCausedTheProblem(status);
}
return StatusModifiedToSayPolicyExhaustionCausedTheProblem(status);
}
// sleep, which may exhaust the policy, even if it was not exhausted in
// the last call.
}
return StatusModifiedToSayPolicyExhaustionCausedTheProblem(status);
Parameter
Name
Description
status
Status const &
Returns
Type
Description
bool
IsExhausted() const
Return true if the retry policy should stop as the retry limit has been reached.
This functions are typically used in a retry loop, where they control whether to continue, whether a failure should be retried, and finally how to format the error message.
std::unique_ptr<RetryPolicy> policy = ....;
Status status;
while (!policy->IsExhausted()) {
auto response = try_rpc(); // typically `response` is StatusOr<T>
if (response.ok()) return response;
status = std::move(response).status();
if (!policy->OnFailure(response->status())) {
if (policy->IsPermanentFailure(response->status()) {
return StatusModifiedToSayPermanentFailureCausedTheProblem(status);
}
return StatusModifiedToSayPolicyExhaustionCausedTheProblem(status);
}
// sleep, which may exhaust the policy, even if it was not exhausted in
// the last call.
}
return StatusModifiedToSayPolicyExhaustionCausedTheProblem(status);
Returns
Type
Description
bool
IsPermanentFailure(Status const &) const
Return true ifstatusis treated as a permanent (and therefore non-retryable) error.
This functions are typically used in a retry loop, where they control whether to continue, whether a failure should be retried, and finally how to format the error message.
std::unique_ptr<RetryPolicy> policy = ....;
Status status;
while (!policy->IsExhausted()) {
auto response = try_rpc(); // typically `response` is StatusOr<T>
if (response.ok()) return response;
status = std::move(response).status();
if (!policy->OnFailure(response->status())) {
if (policy->IsPermanentFailure(response->status()) {
return StatusModifiedToSayPermanentFailureCausedTheProblem(status);
}
return StatusModifiedToSayPolicyExhaustionCausedTheProblem(status);
}
// sleep, which may exhaust the policy, even if it was not exhausted in
// the last call.
}
return StatusModifiedToSayPolicyExhaustionCausedTheProblem(status);
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThe latest version of the \u003ccode\u003eRetryPolicy\u003c/code\u003e documentation is 2.37.0-rc, and the page contains links to versions ranging from 2.10.1 to 2.37.0-rc.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eRetryPolicy\u003c/code\u003e defines an interface for controlling retry behavior in a loop, managing when to continue, when to retry, and formatting error messages.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eOnFailure\u003c/code\u003e function determines if the retry loop should continue after a given status, taking a \u003ccode\u003eStatus const &\u003c/code\u003e as input and returning a boolean.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eIsExhausted\u003c/code\u003e is a function that returns true when the retry limit has been reached and the retry policy should be stopped, and does not take any input parameter.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eIsPermanentFailure\u003c/code\u003e is a function that determines whether a given status is considered a permanent error, and is non-retryable, taking a \u003ccode\u003eStatus const &\u003c/code\u003e parameter, and returning a boolean.\u003c/p\u003e\n"]]],[],null,["# Class RetryPolicy (2.15.1)\n\nVersion 2.15.1keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.41.0](/cpp/docs/reference/common/2.41.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.40.0](/cpp/docs/reference/common/2.40.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.39.0](/cpp/docs/reference/common/2.39.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.38.0](/cpp/docs/reference/common/2.38.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.37.0](/cpp/docs/reference/common/2.37.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.36.0](/cpp/docs/reference/common/2.36.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.35.0](/cpp/docs/reference/common/2.35.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.34.0](/cpp/docs/reference/common/2.34.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.33.0](/cpp/docs/reference/common/2.33.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.32.0](/cpp/docs/reference/common/2.32.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.31.0](/cpp/docs/reference/common/2.31.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.30.0](/cpp/docs/reference/common/2.30.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.29.0](/cpp/docs/reference/common/2.29.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.28.0](/cpp/docs/reference/common/2.28.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.27.0](/cpp/docs/reference/common/2.27.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.26.0](/cpp/docs/reference/common/2.26.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.25.1](/cpp/docs/reference/common/2.25.1/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.24.0](/cpp/docs/reference/common/2.24.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.23.0](/cpp/docs/reference/common/2.23.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.22.1](/cpp/docs/reference/common/2.22.1/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.21.0](/cpp/docs/reference/common/2.21.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.20.0](/cpp/docs/reference/common/2.20.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.19.0](/cpp/docs/reference/common/2.19.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.18.0](/cpp/docs/reference/common/2.18.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.17.0](/cpp/docs/reference/common/2.17.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.16.0](/cpp/docs/reference/common/2.16.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.15.1](/cpp/docs/reference/common/2.15.1/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.14.0](/cpp/docs/reference/common/2.14.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.13.0](/cpp/docs/reference/common/2.13.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.12.0](/cpp/docs/reference/common/2.12.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.11.0](/cpp/docs/reference/common/2.11.0/classgoogle_1_1cloud_1_1RetryPolicy)\n- [2.10.1](/cpp/docs/reference/common/2.10.1/classgoogle_1_1cloud_1_1RetryPolicy) \nDefine the interface for retry policies.\n\nFunctions\n---------\n\n### OnFailure(Status const \\&)\n\nReturn true if the retry loop should continue after `status`. \nThis functions are typically used in a retry loop, where they control whether to continue, whether a failure should be retried, and finally how to format the error message. \n\n std::unique_ptr\u003cRetryPolicy\u003e policy = ....;\n Status status;\n while (!policy-\u003eIsExhausted()) {\n auto response = try_rpc(); // typically `response` is StatusOr\u003cT\u003e\n if (response.ok()) return response;\n status = std::move(response).status();\n if (!policy-\u003eOnFailure(response-\u003estatus())) {\n if (policy-\u003eIsPermanentFailure(response-\u003estatus()) {\n return StatusModifiedToSayPermanentFailureCausedTheProblem(status);\n }\n return StatusModifiedToSayPolicyExhaustionCausedTheProblem(status);\n }\n // sleep, which may exhaust the policy, even if it was not exhausted in\n // the last call.\n }\n return StatusModifiedToSayPolicyExhaustionCausedTheProblem(status);\n\n### IsExhausted() const\n\nReturn true if the retry policy should stop as the retry limit has been reached. \nThis functions are typically used in a retry loop, where they control whether to continue, whether a failure should be retried, and finally how to format the error message. \n\n std::unique_ptr\u003cRetryPolicy\u003e policy = ....;\n Status status;\n while (!policy-\u003eIsExhausted()) {\n auto response = try_rpc(); // typically `response` is StatusOr\u003cT\u003e\n if (response.ok()) return response;\n status = std::move(response).status();\n if (!policy-\u003eOnFailure(response-\u003estatus())) {\n if (policy-\u003eIsPermanentFailure(response-\u003estatus()) {\n return StatusModifiedToSayPermanentFailureCausedTheProblem(status);\n }\n return StatusModifiedToSayPolicyExhaustionCausedTheProblem(status);\n }\n // sleep, which may exhaust the policy, even if it was not exhausted in\n // the last call.\n }\n return StatusModifiedToSayPolicyExhaustionCausedTheProblem(status);\n\n### IsPermanentFailure(Status const \\&) const\n\nReturn true if `status` is treated as a permanent (and therefore non-retryable) error. \nThis functions are typically used in a retry loop, where they control whether to continue, whether a failure should be retried, and finally how to format the error message. \n\n std::unique_ptr\u003cRetryPolicy\u003e policy = ....;\n Status status;\n while (!policy-\u003eIsExhausted()) {\n auto response = try_rpc(); // typically `response` is StatusOr\u003cT\u003e\n if (response.ok()) return response;\n status = std::move(response).status();\n if (!policy-\u003eOnFailure(response-\u003estatus())) {\n if (policy-\u003eIsPermanentFailure(response-\u003estatus()) {\n return StatusModifiedToSayPermanentFailureCausedTheProblem(status);\n }\n return StatusModifiedToSayPolicyExhaustionCausedTheProblem(status);\n }\n // sleep, which may exhaust the policy, even if it was not exhausted in\n // the last call.\n }\n return StatusModifiedToSayPolicyExhaustionCausedTheProblem(status);"]]