3.11.0-rc 3.10.0 (latest) 3.9.0 3.8.0 3.7.0 3.6.0 3.5.0 3.4.0 3.3.0 3.2.0 2.48.0-rc 2.47.1 2.46.0 2.45.0 2.44.0 2.43.0 2.42.0 2.41.0 2.40.0 2.39.0 2.38.0 2.37.0 2.36.0 2.35.0 2.34.0 2.33.0 2.32.0 2.31.0 2.30.0 2.29.0 2.28.0 2.27.0 2.26.0 2.25.1 2.24.0 2.23.0 2.22.1 2.21.0 2.20.0 2.19.0 2.18.0 2.17.0 2.16.0 2.15.1 2.14.0 2.13.0 2.12.0 2.11.0 2.10.1

# Intercepting Unrecoverable Errors

In some rare cases, the client libraries may need to terminate the application because it encounters an unrecoverable error. For example:

- If the application calls [`StatusOr`](https://docs.cloud.google.com/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1StatusOr)`<T>::value()`, and the library was compiled with exceptions disabled, and the [`StatusOr`](https://docs.cloud.google.com/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1StatusOr)`<T>` 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`](https://docs.cloud.google.com/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1StatusOr)`<T>` status (using `.ok()` or `.status()`) and avoid calling `.value()` if the [`StatusOr`](https://docs.cloud.google.com/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1StatusOr)`<T>` is holding an error.
- If the application calls `future<T>::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<`[`StatusOr`](https://docs.cloud.google.com/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1StatusOr)`<T>>` to avoid this problem, but the application may have created `future<T>` and `promise<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 call `std::abort()` when an unrecoverable error occurs.

### Functions

- [`SetTerminateHandler(TerminateHandler)`](about:invalid#zCSafez)
- [`GetTerminateHandler()`](about:invalid#zCSafez)
- [`Terminate(char const *)`](about:invalid#zCSafez)

### Types

- [`TerminateHandler`](about:invalid#zCSafez)