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 document details how to handle unrecoverable errors in client libraries, which may force application termination.\u003c/p\u003e\n"],["\u003cp\u003eThe latest version available for these libraries is version 2.37.0-rc, with a comprehensive list of previous versions provided.\u003c/p\u003e\n"],["\u003cp\u003eUnrecoverable errors, for example, exceptions when exceptions are disabled or a future is satisfied with an exception, prevent the library from functioning correctly, and therefore will terminate the program.\u003c/p\u003e\n"],["\u003cp\u003eWhile the application can't recover from these errors, it can log additional information using functions like \u003ccode\u003eSetTerminateHandler\u003c/code\u003e, \u003ccode\u003eGetTerminateHandler\u003c/code\u003e, and \u003ccode\u003eTerminate\u003c/code\u003e before the program ends.\u003c/p\u003e\n"],["\u003cp\u003eThe default behavior of the client library is to call \u003ccode\u003estd::abort()\u003c/code\u003e when encountering such unrecoverable errors.\u003c/p\u003e\n"]]],[],null,["# Intercepting Unrecoverable Errors (2.42.0-rc)\n\nVersion latestkeyboard_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/latest/classgoogle_1_1cloud_1_1StatusOr)`\u003cT\u003e::value()`, and the library was compiled with exceptions disabled, and the [`StatusOr`](/cpp/docs/reference/common/latest/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/latest/classgoogle_1_1cloud_1_1StatusOr)`\u003cT\u003e` status (using `.ok()` or `.status()`) and avoid calling `.value()` if the [`StatusOr`](/cpp/docs/reference/common/latest/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/latest/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)`](about:invalid#zCSafez)\n- [`GetTerminateHandler()`](about:invalid#zCSafez)\n- [`Terminate(char const *)`](about:invalid#zCSafez)\n\n### Types\n\n- [`TerminateHandler`](about:invalid#zCSafez)"]]