In some rare cases, the client libraries may need to terminate the application because it encounters an unrecoverable error. For example:
If the application callsStatusOr<T>::value(), and the library was compiled with exceptions disabled, and theStatusOr<T>contains an error,thenthe function throws an exception to report the error as the function cannot return a valid value. Applications that disable exceptions should query theStatusOr<T>status (using.ok()or.status()) and avoid calling.value()if theStatusOr<T>is holding an error.
If the application callsfuture<T>::get(), the library was compiled with exceptions disabled, and (somehow) the future is satisfied with an exception. Note that the library APIs typically returnfuture<StatusOr<T>>to avoid this problem, but the application may have createdfuture<T>andpromise<T>pairs in their own code.
In these cases there is no mechanism to return the error. The library cannot continue working correctly and must terminate the program. The application may want to intercept these errors, before the application crashes, and log or otherwise capture additional information to help with debugging or troubleshooting. The functions in this module can be used to do so.
By their nature, there is no mechanism to "handle" and "recover" from unrecoverable errors. All the application can do is log additional information before the program terminates.
Note that the libraries do not use functions that can trigger unrecoverable errors (if they do we consider that a library bug).
The default behavior in the client library is to callstd::abort()when an unrecoverable error occurs.
[[["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\u003eThis page details how to handle unrecoverable errors in client libraries, which may force application termination in certain scenarios.\u003c/p\u003e\n"],["\u003cp\u003eUnrecoverable errors can occur when calling functions like \u003ccode\u003eStatusOr<T>::value()\u003c/code\u003e or \u003ccode\u003efuture<T>::get()\u003c/code\u003e with exceptions disabled, and the functions return an error.\u003c/p\u003e\n"],["\u003cp\u003eThere's no way to recover from these errors, but the provided functions allow for logging or capturing information before the application terminates.\u003c/p\u003e\n"],["\u003cp\u003eThe library's default behavior upon encountering an unrecoverable error is to call \u003ccode\u003estd::abort()\u003c/code\u003e, and it primarily returns \u003ccode\u003efuture<StatusOr<T>>\u003c/code\u003e in order to avoid this issue.\u003c/p\u003e\n"],["\u003cp\u003eThe listed functions, \u003ccode\u003eSetTerminateHandler(TerminateHandler)\u003c/code\u003e, \u003ccode\u003eGetTerminateHandler()\u003c/code\u003e, and \u003ccode\u003eTerminate(char const *)\u003c/code\u003e, along with the type \u003ccode\u003eTerminateHandler\u003c/code\u003e, are provided to intercept errors.\u003c/p\u003e\n"]]],[],null,["# Intercepting Unrecoverable Errors (2.17.0)\n\nVersion 2.17.0keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/common/latest/group__terminate)\n- [2.41.0](/cpp/docs/reference/common/2.41.0/group__terminate)\n- [2.40.0](/cpp/docs/reference/common/2.40.0/group__terminate)\n- [2.39.0](/cpp/docs/reference/common/2.39.0/group__terminate)\n- [2.38.0](/cpp/docs/reference/common/2.38.0/group__terminate)\n- [2.37.0](/cpp/docs/reference/common/2.37.0/group__terminate)\n- [2.36.0](/cpp/docs/reference/common/2.36.0/group__terminate)\n- [2.35.0](/cpp/docs/reference/common/2.35.0/group__terminate)\n- [2.34.0](/cpp/docs/reference/common/2.34.0/group__terminate)\n- [2.33.0](/cpp/docs/reference/common/2.33.0/group__terminate)\n- [2.32.0](/cpp/docs/reference/common/2.32.0/group__terminate)\n- [2.31.0](/cpp/docs/reference/common/2.31.0/group__terminate)\n- [2.30.0](/cpp/docs/reference/common/2.30.0/group__terminate)\n- [2.29.0](/cpp/docs/reference/common/2.29.0/group__terminate)\n- [2.28.0](/cpp/docs/reference/common/2.28.0/group__terminate)\n- [2.27.0](/cpp/docs/reference/common/2.27.0/group__terminate)\n- [2.26.0](/cpp/docs/reference/common/2.26.0/group__terminate)\n- [2.25.1](/cpp/docs/reference/common/2.25.1/group__terminate)\n- [2.24.0](/cpp/docs/reference/common/2.24.0/group__terminate)\n- [2.23.0](/cpp/docs/reference/common/2.23.0/group__terminate)\n- [2.22.1](/cpp/docs/reference/common/2.22.1/group__terminate)\n- [2.21.0](/cpp/docs/reference/common/2.21.0/group__terminate)\n- [2.20.0](/cpp/docs/reference/common/2.20.0/group__terminate)\n- [2.19.0](/cpp/docs/reference/common/2.19.0/group__terminate)\n- [2.18.0](/cpp/docs/reference/common/2.18.0/group__terminate)\n- [2.17.0](/cpp/docs/reference/common/2.17.0/group__terminate)\n- [2.16.0](/cpp/docs/reference/common/2.16.0/group__terminate)\n- [2.15.1](/cpp/docs/reference/common/2.15.1/group__terminate)\n- [2.14.0](/cpp/docs/reference/common/2.14.0/group__terminate)\n- [2.13.0](/cpp/docs/reference/common/2.13.0/group__terminate)\n- [2.12.0](/cpp/docs/reference/common/2.12.0/group__terminate)\n- [2.11.0](/cpp/docs/reference/common/2.11.0/group__terminate)\n- [2.10.1](/cpp/docs/reference/common/2.10.1/group__terminate) \n\nIntercepting Unrecoverable Errors\n=================================\n\nIn some rare cases, the client libraries may need to terminate the application because it encounters an unrecoverable error. For example:\n\n- If the application calls [`StatusOr`](/cpp/docs/reference/common/2.17.0/classgoogle_1_1cloud_1_1StatusOr)`\u003cT\u003e::value()`, and the library was compiled with exceptions disabled, and the [`StatusOr`](/cpp/docs/reference/common/2.17.0/classgoogle_1_1cloud_1_1StatusOr)`\u003cT\u003e` contains an error, *then* the function throws an exception to report the error as the function cannot return a valid value. Applications that disable exceptions should query the [`StatusOr`](/cpp/docs/reference/common/2.17.0/classgoogle_1_1cloud_1_1StatusOr)`\u003cT\u003e` status (using `.ok()` or `.status()`) and avoid calling `.value()` if the [`StatusOr`](/cpp/docs/reference/common/2.17.0/classgoogle_1_1cloud_1_1StatusOr)`\u003cT\u003e` is holding an error.\n- If the application calls `future\u003cT\u003e::get()`, the library was compiled with exceptions disabled, and (somehow) the future is satisfied with an exception. Note that the library APIs typically return `future\u003c`[`StatusOr`](/cpp/docs/reference/common/2.17.0/classgoogle_1_1cloud_1_1StatusOr)`\u003cT\u003e\u003e` to avoid this problem, but the application may have created `future\u003cT\u003e` and `promise\u003cT\u003e` pairs in their own code.\n\nIn these cases there is no mechanism to return the error. The library cannot continue working correctly and must terminate the program. The application may want to intercept these errors, before the application crashes, and log or otherwise capture additional information to help with debugging or troubleshooting. The functions in this module can be used to do so.\n\nBy their nature, there is no mechanism to \"handle\" and \"recover\" from unrecoverable errors. All the application can do is log additional information before the program terminates.\n\nNote that the libraries do not use functions that can trigger unrecoverable errors (if they do we consider that a library bug).\n\nThe default behavior in the client library is to call `std::abort()` when an unrecoverable error occurs.\n\n### Functions\n\n- [`SetTerminateHandler(TerminateHandler)`](/cpp/docs/reference/common/2.17.0/namespacegoogle_1_1cloud)\n- [`GetTerminateHandler()`](/cpp/docs/reference/common/2.17.0/namespacegoogle_1_1cloud)\n- [`Terminate(char const *)`](/cpp/docs/reference/common/2.17.0/namespacegoogle_1_1cloud)\n\n### Types\n\n- [`TerminateHandler`](/cpp/docs/reference/common/2.17.0/namespacegoogle_1_1cloud)"]]