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 
16 
17 #include <cstdlib>
18 #include <functional>
19 #include <new>
20 #include <stdexcept>
21 #include "absl/base/config.h"
23 
24 namespace absl {
25 namespace base_internal {
26 
27 namespace {
28 template <typename T>
29 [[noreturn]] void Throw(const T& error) {
30 #ifdef ABSL_HAVE_EXCEPTIONS
31  throw error;
32 #else
33  ABSL_RAW_LOG(FATAL, "%s", error.what());
34  std::abort();
35 #endif
36 }
37 } // namespace
38 
39 void ThrowStdLogicError(const std::string& what_arg) {
40  Throw(std::logic_error(what_arg));
41 }
42 void ThrowStdLogicError(const char* what_arg) {
43  Throw(std::logic_error(what_arg));
44 }
45 void ThrowStdInvalidArgument(const std::string& what_arg) {
46  Throw(std::invalid_argument(what_arg));
47 }
48 void ThrowStdInvalidArgument(const char* what_arg) {
49  Throw(std::invalid_argument(what_arg));
50 }
51 
52 void ThrowStdDomainError(const std::string& what_arg) {
53  Throw(std::domain_error(what_arg));
54 }
55 void ThrowStdDomainError(const char* what_arg) {
56  Throw(std::domain_error(what_arg));
57 }
58 
59 void ThrowStdLengthError(const std::string& what_arg) {
60  Throw(std::length_error(what_arg));
61 }
62 void ThrowStdLengthError(const char* what_arg) {
63  Throw(std::length_error(what_arg));
64 }
65 
66 void ThrowStdOutOfRange(const std::string& what_arg) {
67  Throw(std::out_of_range(what_arg));
68 }
69 void ThrowStdOutOfRange(const char* what_arg) {
70  Throw(std::out_of_range(what_arg));
71 }
72 
73 void ThrowStdRuntimeError(const std::string& what_arg) {
74  Throw(std::runtime_error(what_arg));
75 }
76 void ThrowStdRuntimeError(const char* what_arg) {
77  Throw(std::runtime_error(what_arg));
78 }
79 
80 void ThrowStdRangeError(const std::string& what_arg) {
81  Throw(std::range_error(what_arg));
82 }
83 void ThrowStdRangeError(const char* what_arg) {
84  Throw(std::range_error(what_arg));
85 }
86 
87 void ThrowStdOverflowError(const std::string& what_arg) {
88  Throw(std::overflow_error(what_arg));
89 }
90 void ThrowStdOverflowError(const char* what_arg) {
91  Throw(std::overflow_error(what_arg));
92 }
93 
94 void ThrowStdUnderflowError(const std::string& what_arg) {
95  Throw(std::underflow_error(what_arg));
96 }
97 void ThrowStdUnderflowError(const char* what_arg) {
98  Throw(std::underflow_error(what_arg));
99 }
100 
101 void ThrowStdBadFunctionCall() { Throw(std::bad_function_call()); }
102 
103 void ThrowStdBadAlloc() { Throw(std::bad_alloc()); }
104 
105 } // namespace base_internal
106 } // namespace absl
void ThrowStdLogicError(const std::string &what_arg)
void ThrowStdInvalidArgument(const std::string &what_arg)
void ThrowStdLengthError(const std::string &what_arg)
#define ABSL_RAW_LOG(severity,...)
Definition: raw_logging.h:42
void ThrowStdOutOfRange(const std::string &what_arg)
Definition: algorithm.h:29
void ThrowStdDomainError(const std::string &what_arg)
void ThrowStdRuntimeError(const std::string &what_arg)
void ThrowStdRangeError(const std::string &what_arg)
void ThrowStdUnderflowError(const std::string &what_arg)
void ThrowStdOverflowError(const std::string &what_arg)


abseil_cpp
Author(s):
autogenerated on Mon Feb 28 2022 21:31:20