Google Cloud C++ Client  2.7.0
C++ Client Library for Google Cloud Platform
terminate_handler.h
Go to the documentation of this file.
1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_TERMINATE_HANDLER_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_TERMINATE_HANDLER_H
17 
18 #include "google/cloud/version.h"
19 #include <functional>
20 
21 namespace google {
22 namespace cloud {
24 /**
25  * @defgroup terminate Control behavior on unrecoverable errors.
26  *
27  * If exceptions are not enabled via `GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS`, calling
28  * any function from throw_delegate.h will result in calling the handler
29  * installed via this API. By default, the library calls `std::abort()`.
30  */
31 
32 /**
33  * Terminate handler.
34  *
35  * It should handle the error, whose description are given in *msg* and should
36  * never return.
37  *
38  * @ingroup terminate
39  */
40 using TerminateHandler = std::function<void(char const* msg)>;
41 
42 /**
43  * Install terminate handler and get the old one atomically.
44  *
45  * @param f the handler. It should never return, behaviour is undefined
46  * otherwise.
47  *
48  * @return Previously set handler.
49  *
50  * @ingroup terminate
51  */
52 TerminateHandler SetTerminateHandler(TerminateHandler f);
53 
54 /**
55  * Get the currently installed handler.
56  *
57  * @return The currently installed handler.
58  *
59  * @ingroup terminate
60  */
61 TerminateHandler GetTerminateHandler();
62 
63 /**
64  * Invoke the currently installed handler.
65  *
66  * @param msg Details about the error.
67  *
68  * This function should never return.
69  *
70  * @ingroup terminate
71  */
72 [[noreturn]] void Terminate(char const* msg);
73 
75 } // namespace cloud
76 } // namespace google
77 
78 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_TERMINATE_HANDLER_H