1*9356374aSAndroid Build Coastguard Worker // 2*9356374aSAndroid Build Coastguard Worker // Copyright 2017 The Abseil Authors. 3*9356374aSAndroid Build Coastguard Worker // 4*9356374aSAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 5*9356374aSAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 6*9356374aSAndroid Build Coastguard Worker // You may obtain a copy of the License at 7*9356374aSAndroid Build Coastguard Worker // 8*9356374aSAndroid Build Coastguard Worker // https://www.apache.org/licenses/LICENSE-2.0 9*9356374aSAndroid Build Coastguard Worker // 10*9356374aSAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 11*9356374aSAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 12*9356374aSAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*9356374aSAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 14*9356374aSAndroid Build Coastguard Worker // limitations under the License. 15*9356374aSAndroid Build Coastguard Worker // 16*9356374aSAndroid Build Coastguard Worker 17*9356374aSAndroid Build Coastguard Worker #ifndef ABSL_BASE_INTERNAL_THROW_DELEGATE_H_ 18*9356374aSAndroid Build Coastguard Worker #define ABSL_BASE_INTERNAL_THROW_DELEGATE_H_ 19*9356374aSAndroid Build Coastguard Worker 20*9356374aSAndroid Build Coastguard Worker #include <string> 21*9356374aSAndroid Build Coastguard Worker 22*9356374aSAndroid Build Coastguard Worker #include "absl/base/config.h" 23*9356374aSAndroid Build Coastguard Worker 24*9356374aSAndroid Build Coastguard Worker namespace absl { 25*9356374aSAndroid Build Coastguard Worker ABSL_NAMESPACE_BEGIN 26*9356374aSAndroid Build Coastguard Worker namespace base_internal { 27*9356374aSAndroid Build Coastguard Worker 28*9356374aSAndroid Build Coastguard Worker // Helper functions that allow throwing exceptions consistently from anywhere. 29*9356374aSAndroid Build Coastguard Worker // The main use case is for header-based libraries (eg templates), as they will 30*9356374aSAndroid Build Coastguard Worker // be built by many different targets with their own compiler options. 31*9356374aSAndroid Build Coastguard Worker // In particular, this will allow a safe way to throw exceptions even if the 32*9356374aSAndroid Build Coastguard Worker // caller is compiled with -fno-exceptions. This is intended for implementing 33*9356374aSAndroid Build Coastguard Worker // things like map<>::at(), which the standard documents as throwing an 34*9356374aSAndroid Build Coastguard Worker // exception on error. 35*9356374aSAndroid Build Coastguard Worker // 36*9356374aSAndroid Build Coastguard Worker // Using other techniques like #if tricks could lead to ODR violations. 37*9356374aSAndroid Build Coastguard Worker // 38*9356374aSAndroid Build Coastguard Worker // You shouldn't use it unless you're writing code that you know will be built 39*9356374aSAndroid Build Coastguard Worker // both with and without exceptions and you need to conform to an interface 40*9356374aSAndroid Build Coastguard Worker // that uses exceptions. 41*9356374aSAndroid Build Coastguard Worker 42*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdLogicError(const std::string& what_arg); 43*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdLogicError(const char* what_arg); 44*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdInvalidArgument(const std::string& what_arg); 45*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdInvalidArgument(const char* what_arg); 46*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdDomainError(const std::string& what_arg); 47*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdDomainError(const char* what_arg); 48*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdLengthError(const std::string& what_arg); 49*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdLengthError(const char* what_arg); 50*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdOutOfRange(const std::string& what_arg); 51*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdOutOfRange(const char* what_arg); 52*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdRuntimeError(const std::string& what_arg); 53*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdRuntimeError(const char* what_arg); 54*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdRangeError(const std::string& what_arg); 55*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdRangeError(const char* what_arg); 56*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdOverflowError(const std::string& what_arg); 57*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdOverflowError(const char* what_arg); 58*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdUnderflowError(const std::string& what_arg); 59*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdUnderflowError(const char* what_arg); 60*9356374aSAndroid Build Coastguard Worker 61*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdBadFunctionCall(); 62*9356374aSAndroid Build Coastguard Worker [[noreturn]] void ThrowStdBadAlloc(); 63*9356374aSAndroid Build Coastguard Worker 64*9356374aSAndroid Build Coastguard Worker // ThrowStdBadArrayNewLength() cannot be consistently supported because 65*9356374aSAndroid Build Coastguard Worker // std::bad_array_new_length is missing in libstdc++ until 4.9.0. 66*9356374aSAndroid Build Coastguard Worker // https://gcc.gnu.org/onlinedocs/gcc-4.8.3/libstdc++/api/a01379_source.html 67*9356374aSAndroid Build Coastguard Worker // https://gcc.gnu.org/onlinedocs/gcc-4.9.0/libstdc++/api/a01327_source.html 68*9356374aSAndroid Build Coastguard Worker // libcxx (as of 3.2) and msvc (as of 2015) both have it. 69*9356374aSAndroid Build Coastguard Worker // [[noreturn]] void ThrowStdBadArrayNewLength(); 70*9356374aSAndroid Build Coastguard Worker 71*9356374aSAndroid Build Coastguard Worker } // namespace base_internal 72*9356374aSAndroid Build Coastguard Worker ABSL_NAMESPACE_END 73*9356374aSAndroid Build Coastguard Worker } // namespace absl 74*9356374aSAndroid Build Coastguard Worker 75*9356374aSAndroid Build Coastguard Worker #endif // ABSL_BASE_INTERNAL_THROW_DELEGATE_H_ 76