throw_delegate.cc
Go to the documentation of this file.
00001 // Copyright 2017 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
00014 
00015 #include "absl/base/internal/throw_delegate.h"
00016 
00017 #include <cstdlib>
00018 #include <functional>
00019 #include <new>
00020 #include <stdexcept>
00021 #include "absl/base/config.h"
00022 #include "absl/base/internal/raw_logging.h"
00023 
00024 namespace absl {
00025 namespace base_internal {
00026 
00027 namespace {
00028 template <typename T>
00029 [[noreturn]] void Throw(const T& error) {
00030 #ifdef ABSL_HAVE_EXCEPTIONS
00031   throw error;
00032 #else
00033   ABSL_RAW_LOG(FATAL, "%s", error.what());
00034   std::abort();
00035 #endif
00036 }
00037 }  // namespace
00038 
00039 void ThrowStdLogicError(const std::string& what_arg) {
00040   Throw(std::logic_error(what_arg));
00041 }
00042 void ThrowStdLogicError(const char* what_arg) {
00043   Throw(std::logic_error(what_arg));
00044 }
00045 void ThrowStdInvalidArgument(const std::string& what_arg) {
00046   Throw(std::invalid_argument(what_arg));
00047 }
00048 void ThrowStdInvalidArgument(const char* what_arg) {
00049   Throw(std::invalid_argument(what_arg));
00050 }
00051 
00052 void ThrowStdDomainError(const std::string& what_arg) {
00053   Throw(std::domain_error(what_arg));
00054 }
00055 void ThrowStdDomainError(const char* what_arg) {
00056   Throw(std::domain_error(what_arg));
00057 }
00058 
00059 void ThrowStdLengthError(const std::string& what_arg) {
00060   Throw(std::length_error(what_arg));
00061 }
00062 void ThrowStdLengthError(const char* what_arg) {
00063   Throw(std::length_error(what_arg));
00064 }
00065 
00066 void ThrowStdOutOfRange(const std::string& what_arg) {
00067   Throw(std::out_of_range(what_arg));
00068 }
00069 void ThrowStdOutOfRange(const char* what_arg) {
00070   Throw(std::out_of_range(what_arg));
00071 }
00072 
00073 void ThrowStdRuntimeError(const std::string& what_arg) {
00074   Throw(std::runtime_error(what_arg));
00075 }
00076 void ThrowStdRuntimeError(const char* what_arg) {
00077   Throw(std::runtime_error(what_arg));
00078 }
00079 
00080 void ThrowStdRangeError(const std::string& what_arg) {
00081   Throw(std::range_error(what_arg));
00082 }
00083 void ThrowStdRangeError(const char* what_arg) {
00084   Throw(std::range_error(what_arg));
00085 }
00086 
00087 void ThrowStdOverflowError(const std::string& what_arg) {
00088   Throw(std::overflow_error(what_arg));
00089 }
00090 void ThrowStdOverflowError(const char* what_arg) {
00091   Throw(std::overflow_error(what_arg));
00092 }
00093 
00094 void ThrowStdUnderflowError(const std::string& what_arg) {
00095   Throw(std::underflow_error(what_arg));
00096 }
00097 void ThrowStdUnderflowError(const char* what_arg) {
00098   Throw(std::underflow_error(what_arg));
00099 }
00100 
00101 void ThrowStdBadFunctionCall() { Throw(std::bad_function_call()); }
00102 
00103 void ThrowStdBadAlloc() { Throw(std::bad_alloc()); }
00104 
00105 }  // namespace base_internal
00106 }  // namespace absl


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:15