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 lead to application termination when they occur.\u003c/p\u003e\n"],["\u003cp\u003eThe library will terminate the program when there is no way to return an error, and continuing is not possible, such as when \u003ccode\u003eStatusOr<T>::value()\u003c/code\u003e or \u003ccode\u003efuture<T>::get()\u003c/code\u003e encounters an error while exceptions are disabled.\u003c/p\u003e\n"],["\u003cp\u003eWhile there's no way to recover from these errors, the functions \u003ccode\u003eSetTerminateHandler\u003c/code\u003e, \u003ccode\u003eGetTerminateHandler\u003c/code\u003e, and \u003ccode\u003eTerminate\u003c/code\u003e can be utilized to intercept and log these errors before the application crashes.\u003c/p\u003e\n"],["\u003cp\u003eThe default behavior of the client library in the event of an unrecoverable error is to call \u003ccode\u003estd::abort()\u003c/code\u003e, immediately ending the program.\u003c/p\u003e\n"],["\u003cp\u003eThe content covered within these pages spans across multiple library versions, starting from version 2.10.1 and going all the way up to the most current release, version 2.37.0-rc, while also covering the common 2.18.0 functions for this error handling.\u003c/p\u003e\n"]]],[],null,["# Intercepting Unrecoverable Errors (2.18.0)\n\nVersion 2.18.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.18.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.18.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.18.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.18.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.18.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.18.0/namespacegoogle_1_1cloud)\n- [`GetTerminateHandler()`](/cpp/docs/reference/common/2.18.0/namespacegoogle_1_1cloud)\n- [`Terminate(char const *)`](/cpp/docs/reference/common/2.18.0/namespacegoogle_1_1cloud)\n\n### Types\n\n- [`TerminateHandler`](/cpp/docs/reference/common/2.18.0/namespacegoogle_1_1cloud)"]]