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