abseil-cpp/absl/base/internal/throw_delegate.cc
Go to the documentation of this file.
1 // Copyright 2017 The Abseil Authors.
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 #include "absl/base/internal/throw_delegate.h"
16 
17 #include <cstdlib>
18 #include <functional>
19 #include <new>
20 #include <stdexcept>
21 
22 #include "absl/base/config.h"
23 #include "absl/base/internal/raw_logging.h"
24 
25 namespace absl {
27 namespace base_internal {
28 
29 // NOTE: The various STL exception throwing functions are placed within the
30 // #ifdef blocks so the symbols aren't exposed on platforms that don't support
31 // them, such as the Android NDK. For example, ANGLE fails to link when building
32 // within AOSP without them, since the STL functions don't exist.
33 namespace {
34 #ifdef ABSL_HAVE_EXCEPTIONS
35 template <typename T>
36 [[noreturn]] void Throw(const T& error) {
37  throw error;
38 }
39 #endif
40 } // namespace
41 
42 void ThrowStdLogicError(const std::string& what_arg) {
43 #ifdef ABSL_HAVE_EXCEPTIONS
44  Throw(std::logic_error(what_arg));
45 #else
46  ABSL_RAW_LOG(FATAL, "%s", what_arg.c_str());
47  std::abort();
48 #endif
49 }
50 void ThrowStdLogicError(const char* what_arg) {
51 #ifdef ABSL_HAVE_EXCEPTIONS
52  Throw(std::logic_error(what_arg));
53 #else
54  ABSL_RAW_LOG(FATAL, "%s", what_arg);
55  std::abort();
56 #endif
57 }
58 void ThrowStdInvalidArgument(const std::string& what_arg) {
59 #ifdef ABSL_HAVE_EXCEPTIONS
60  Throw(std::invalid_argument(what_arg));
61 #else
62  ABSL_RAW_LOG(FATAL, "%s", what_arg.c_str());
63  std::abort();
64 #endif
65 }
66 void ThrowStdInvalidArgument(const char* what_arg) {
67 #ifdef ABSL_HAVE_EXCEPTIONS
68  Throw(std::invalid_argument(what_arg));
69 #else
70  ABSL_RAW_LOG(FATAL, "%s", what_arg);
71  std::abort();
72 #endif
73 }
74 
75 void ThrowStdDomainError(const std::string& what_arg) {
76 #ifdef ABSL_HAVE_EXCEPTIONS
77  Throw(std::domain_error(what_arg));
78 #else
79  ABSL_RAW_LOG(FATAL, "%s", what_arg.c_str());
80  std::abort();
81 #endif
82 }
83 void ThrowStdDomainError(const char* what_arg) {
84 #ifdef ABSL_HAVE_EXCEPTIONS
85  Throw(std::domain_error(what_arg));
86 #else
87  ABSL_RAW_LOG(FATAL, "%s", what_arg);
88  std::abort();
89 #endif
90 }
91 
92 void ThrowStdLengthError(const std::string& what_arg) {
93 #ifdef ABSL_HAVE_EXCEPTIONS
94  Throw(std::length_error(what_arg));
95 #else
96  ABSL_RAW_LOG(FATAL, "%s", what_arg.c_str());
97  std::abort();
98 #endif
99 }
100 void ThrowStdLengthError(const char* what_arg) {
101 #ifdef ABSL_HAVE_EXCEPTIONS
102  Throw(std::length_error(what_arg));
103 #else
104  ABSL_RAW_LOG(FATAL, "%s", what_arg);
105  std::abort();
106 #endif
107 }
108 
109 void ThrowStdOutOfRange(const std::string& what_arg) {
110 #ifdef ABSL_HAVE_EXCEPTIONS
111  Throw(std::out_of_range(what_arg));
112 #else
113  ABSL_RAW_LOG(FATAL, "%s", what_arg.c_str());
114  std::abort();
115 #endif
116 }
117 void ThrowStdOutOfRange(const char* what_arg) {
118 #ifdef ABSL_HAVE_EXCEPTIONS
119  Throw(std::out_of_range(what_arg));
120 #else
121  ABSL_RAW_LOG(FATAL, "%s", what_arg);
122  std::abort();
123 #endif
124 }
125 
126 void ThrowStdRuntimeError(const std::string& what_arg) {
127 #ifdef ABSL_HAVE_EXCEPTIONS
128  Throw(std::runtime_error(what_arg));
129 #else
130  ABSL_RAW_LOG(FATAL, "%s", what_arg.c_str());
131  std::abort();
132 #endif
133 }
134 void ThrowStdRuntimeError(const char* what_arg) {
135 #ifdef ABSL_HAVE_EXCEPTIONS
136  Throw(std::runtime_error(what_arg));
137 #else
138  ABSL_RAW_LOG(FATAL, "%s", what_arg);
139  std::abort();
140 #endif
141 }
142 
143 void ThrowStdRangeError(const std::string& what_arg) {
144 #ifdef ABSL_HAVE_EXCEPTIONS
145  Throw(std::range_error(what_arg));
146 #else
147  ABSL_RAW_LOG(FATAL, "%s", what_arg.c_str());
148  std::abort();
149 #endif
150 }
151 void ThrowStdRangeError(const char* what_arg) {
152 #ifdef ABSL_HAVE_EXCEPTIONS
153  Throw(std::range_error(what_arg));
154 #else
155  ABSL_RAW_LOG(FATAL, "%s", what_arg);
156  std::abort();
157 #endif
158 }
159 
160 void ThrowStdOverflowError(const std::string& what_arg) {
161 #ifdef ABSL_HAVE_EXCEPTIONS
162  Throw(std::overflow_error(what_arg));
163 #else
164  ABSL_RAW_LOG(FATAL, "%s", what_arg.c_str());
165  std::abort();
166 #endif
167 }
168 void ThrowStdOverflowError(const char* what_arg) {
169 #ifdef ABSL_HAVE_EXCEPTIONS
170  Throw(std::overflow_error(what_arg));
171 #else
172  ABSL_RAW_LOG(FATAL, "%s", what_arg);
173  std::abort();
174 #endif
175 }
176 
177 void ThrowStdUnderflowError(const std::string& what_arg) {
178 #ifdef ABSL_HAVE_EXCEPTIONS
179  Throw(std::underflow_error(what_arg));
180 #else
181  ABSL_RAW_LOG(FATAL, "%s", what_arg.c_str());
182  std::abort();
183 #endif
184 }
185 void ThrowStdUnderflowError(const char* what_arg) {
186 #ifdef ABSL_HAVE_EXCEPTIONS
187  Throw(std::underflow_error(what_arg));
188 #else
189  ABSL_RAW_LOG(FATAL, "%s", what_arg);
190  std::abort();
191 #endif
192 }
193 
195 #ifdef ABSL_HAVE_EXCEPTIONS
196  Throw(std::bad_function_call());
197 #else
198  std::abort();
199 #endif
200 }
201 
203 #ifdef ABSL_HAVE_EXCEPTIONS
204  Throw(std::bad_alloc());
205 #else
206  std::abort();
207 #endif
208 }
209 
210 } // namespace base_internal
212 } // namespace absl
absl::base_internal::ThrowStdRangeError
void ThrowStdRangeError(const std::string &what_arg)
Definition: abseil-cpp/absl/base/internal/throw_delegate.cc:143
absl::base_internal::ThrowStdLengthError
void ThrowStdLengthError(const std::string &what_arg)
Definition: abseil-cpp/absl/base/internal/throw_delegate.cc:92
absl::base_internal::ThrowStdDomainError
void ThrowStdDomainError(const std::string &what_arg)
Definition: abseil-cpp/absl/base/internal/throw_delegate.cc:75
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
error
grpc_error_handle error
Definition: retry_filter.cc:499
absl::base_internal::ThrowStdRuntimeError
void ThrowStdRuntimeError(const std::string &what_arg)
Definition: abseil-cpp/absl/base/internal/throw_delegate.cc:126
absl::base_internal::ThrowStdInvalidArgument
void ThrowStdInvalidArgument(const std::string &what_arg)
Definition: abseil-cpp/absl/base/internal/throw_delegate.cc:58
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
absl::base_internal::ThrowStdLogicError
void ThrowStdLogicError(const std::string &what_arg)
Definition: abseil-cpp/absl/base/internal/throw_delegate.cc:42
T
#define T(upbtypeconst, upbtype, ctype, default_value)
absl::base_internal::ThrowStdOutOfRange
void ThrowStdOutOfRange(const std::string &what_arg)
Definition: abseil-cpp/absl/base/internal/throw_delegate.cc:109
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
absl::base_internal::ThrowStdBadFunctionCall
void ThrowStdBadFunctionCall()
Definition: abseil-cpp/absl/base/internal/throw_delegate.cc:194
absl::base_internal::ThrowStdUnderflowError
void ThrowStdUnderflowError(const std::string &what_arg)
Definition: abseil-cpp/absl/base/internal/throw_delegate.cc:177
absl::base_internal::ThrowStdBadAlloc
void ThrowStdBadAlloc()
Definition: abseil-cpp/absl/base/internal/throw_delegate.cc:202
FATAL
#define FATAL(msg)
Definition: task.h:88
bloaty::Throw
ABSL_ATTRIBUTE_NORETURN void Throw(const char *str, int line)
Definition: third_party/bloaty/src/util.cc:22
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
absl::base_internal::ThrowStdOverflowError
void ThrowStdOverflowError(const std::string &what_arg)
Definition: abseil-cpp/absl/base/internal/throw_delegate.cc:160
ABSL_RAW_LOG
#define ABSL_RAW_LOG(severity,...)
Definition: abseil-cpp/absl/base/internal/raw_logging.h:44


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:36