287 lines · plain
1// -*- C++ -*-2//===----------------------------------------------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP___CXX03_STDEXCEPT11#define _LIBCPP___CXX03_STDEXCEPT12 13/*14 stdexcept synopsis15 16namespace std17{18 19class logic_error;20class domain_error;21class invalid_argument;22class length_error;23class out_of_range;24class runtime_error;25class range_error;26class overflow_error;27class underflow_error;28 29for each class xxx_error:30 31class xxx_error : public exception // at least indirectly32{33public:34 explicit xxx_error(const string& what_arg);35 explicit xxx_error(const char* what_arg);36 37 virtual const char* what() const noexcept // returns what_arg38};39 40} // std41 42*/43 44#include <__cxx03/__config>45#include <__cxx03/__exception/exception.h>46#include <__cxx03/__fwd/string.h>47#include <__cxx03/__verbose_abort>48 49#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)50# pragma GCC system_header51#endif52 53_LIBCPP_BEGIN_NAMESPACE_STD54 55#ifndef _LIBCPP_ABI_VCRUNTIME56class _LIBCPP_HIDDEN __libcpp_refstring {57 const char* __imp_;58 59 bool __uses_refcount() const;60 61public:62 explicit __libcpp_refstring(const char* __msg);63 __libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT;64 __libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT;65 ~__libcpp_refstring();66 67 _LIBCPP_HIDE_FROM_ABI const char* c_str() const _NOEXCEPT { return __imp_; }68};69#endif // !_LIBCPP_ABI_VCRUNTIME70 71_LIBCPP_END_NAMESPACE_STD72 73namespace std // purposefully not using versioning namespace74{75 76class _LIBCPP_EXPORTED_FROM_ABI logic_error : public exception {77#ifndef _LIBCPP_ABI_VCRUNTIME78 79private:80 std::__libcpp_refstring __imp_;81 82public:83 explicit logic_error(const string&);84 explicit logic_error(const char*);85 86 logic_error(const logic_error&) _NOEXCEPT;87 logic_error& operator=(const logic_error&) _NOEXCEPT;88 89 ~logic_error() _NOEXCEPT override;90 91 const char* what() const _NOEXCEPT override;92#else93 94public:95 explicit logic_error(const std::string&); // Symbol uses versioned std::string96 _LIBCPP_HIDE_FROM_ABI explicit logic_error(const char* __s) : exception(__s) {}97#endif98};99 100class _LIBCPP_EXPORTED_FROM_ABI runtime_error : public exception {101#ifndef _LIBCPP_ABI_VCRUNTIME102 103private:104 std::__libcpp_refstring __imp_;105 106public:107 explicit runtime_error(const string&);108 explicit runtime_error(const char*);109 110 runtime_error(const runtime_error&) _NOEXCEPT;111 runtime_error& operator=(const runtime_error&) _NOEXCEPT;112 113 ~runtime_error() _NOEXCEPT override;114 115 const char* what() const _NOEXCEPT override;116#else117 118public:119 explicit runtime_error(const std::string&); // Symbol uses versioned std::string120 _LIBCPP_HIDE_FROM_ABI explicit runtime_error(const char* __s) : exception(__s) {}121#endif // _LIBCPP_ABI_VCRUNTIME122};123 124class _LIBCPP_EXPORTED_FROM_ABI domain_error : public logic_error {125public:126 _LIBCPP_HIDE_FROM_ABI explicit domain_error(const string& __s) : logic_error(__s) {}127 _LIBCPP_HIDE_FROM_ABI explicit domain_error(const char* __s) : logic_error(__s) {}128 129#ifndef _LIBCPP_ABI_VCRUNTIME130 _LIBCPP_HIDE_FROM_ABI domain_error(const domain_error&) _NOEXCEPT = default;131 _LIBCPP_HIDE_FROM_ABI domain_error& operator=(const domain_error&) _NOEXCEPT = default;132 ~domain_error() _NOEXCEPT override;133#endif134};135 136class _LIBCPP_EXPORTED_FROM_ABI invalid_argument : public logic_error {137public:138 _LIBCPP_HIDE_FROM_ABI explicit invalid_argument(const string& __s) : logic_error(__s) {}139 _LIBCPP_HIDE_FROM_ABI explicit invalid_argument(const char* __s) : logic_error(__s) {}140 141#ifndef _LIBCPP_ABI_VCRUNTIME142 _LIBCPP_HIDE_FROM_ABI invalid_argument(const invalid_argument&) _NOEXCEPT = default;143 _LIBCPP_HIDE_FROM_ABI invalid_argument& operator=(const invalid_argument&) _NOEXCEPT = default;144 ~invalid_argument() _NOEXCEPT override;145#endif146};147 148class _LIBCPP_EXPORTED_FROM_ABI length_error : public logic_error {149public:150 _LIBCPP_HIDE_FROM_ABI explicit length_error(const string& __s) : logic_error(__s) {}151 _LIBCPP_HIDE_FROM_ABI explicit length_error(const char* __s) : logic_error(__s) {}152#ifndef _LIBCPP_ABI_VCRUNTIME153 _LIBCPP_HIDE_FROM_ABI length_error(const length_error&) _NOEXCEPT = default;154 _LIBCPP_HIDE_FROM_ABI length_error& operator=(const length_error&) _NOEXCEPT = default;155 ~length_error() _NOEXCEPT override;156#endif157};158 159class _LIBCPP_EXPORTED_FROM_ABI out_of_range : public logic_error {160public:161 _LIBCPP_HIDE_FROM_ABI explicit out_of_range(const string& __s) : logic_error(__s) {}162 _LIBCPP_HIDE_FROM_ABI explicit out_of_range(const char* __s) : logic_error(__s) {}163 164#ifndef _LIBCPP_ABI_VCRUNTIME165 _LIBCPP_HIDE_FROM_ABI out_of_range(const out_of_range&) _NOEXCEPT = default;166 _LIBCPP_HIDE_FROM_ABI out_of_range& operator=(const out_of_range&) _NOEXCEPT = default;167 ~out_of_range() _NOEXCEPT override;168#endif169};170 171class _LIBCPP_EXPORTED_FROM_ABI range_error : public runtime_error {172public:173 _LIBCPP_HIDE_FROM_ABI explicit range_error(const string& __s) : runtime_error(__s) {}174 _LIBCPP_HIDE_FROM_ABI explicit range_error(const char* __s) : runtime_error(__s) {}175 176#ifndef _LIBCPP_ABI_VCRUNTIME177 _LIBCPP_HIDE_FROM_ABI range_error(const range_error&) _NOEXCEPT = default;178 _LIBCPP_HIDE_FROM_ABI range_error& operator=(const range_error&) _NOEXCEPT = default;179 ~range_error() _NOEXCEPT override;180#endif181};182 183class _LIBCPP_EXPORTED_FROM_ABI overflow_error : public runtime_error {184public:185 _LIBCPP_HIDE_FROM_ABI explicit overflow_error(const string& __s) : runtime_error(__s) {}186 _LIBCPP_HIDE_FROM_ABI explicit overflow_error(const char* __s) : runtime_error(__s) {}187 188#ifndef _LIBCPP_ABI_VCRUNTIME189 _LIBCPP_HIDE_FROM_ABI overflow_error(const overflow_error&) _NOEXCEPT = default;190 _LIBCPP_HIDE_FROM_ABI overflow_error& operator=(const overflow_error&) _NOEXCEPT = default;191 ~overflow_error() _NOEXCEPT override;192#endif193};194 195class _LIBCPP_EXPORTED_FROM_ABI underflow_error : public runtime_error {196public:197 _LIBCPP_HIDE_FROM_ABI explicit underflow_error(const string& __s) : runtime_error(__s) {}198 _LIBCPP_HIDE_FROM_ABI explicit underflow_error(const char* __s) : runtime_error(__s) {}199 200#ifndef _LIBCPP_ABI_VCRUNTIME201 _LIBCPP_HIDE_FROM_ABI underflow_error(const underflow_error&) _NOEXCEPT = default;202 _LIBCPP_HIDE_FROM_ABI underflow_error& operator=(const underflow_error&) _NOEXCEPT = default;203 ~underflow_error() _NOEXCEPT override;204#endif205};206 207} // namespace std208 209_LIBCPP_BEGIN_NAMESPACE_STD210 211// in the dylib212_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_runtime_error(const char*);213 214_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_logic_error(const char* __msg) {215#ifndef _LIBCPP_HAS_NO_EXCEPTIONS216 throw logic_error(__msg);217#else218 _LIBCPP_VERBOSE_ABORT("logic_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);219#endif220}221 222_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_domain_error(const char* __msg) {223#ifndef _LIBCPP_HAS_NO_EXCEPTIONS224 throw domain_error(__msg);225#else226 _LIBCPP_VERBOSE_ABORT("domain_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);227#endif228}229 230_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_invalid_argument(const char* __msg) {231#ifndef _LIBCPP_HAS_NO_EXCEPTIONS232 throw invalid_argument(__msg);233#else234 _LIBCPP_VERBOSE_ABORT("invalid_argument was thrown in -fno-exceptions mode with message \"%s\"", __msg);235#endif236}237 238_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_length_error(const char* __msg) {239#ifndef _LIBCPP_HAS_NO_EXCEPTIONS240 throw length_error(__msg);241#else242 _LIBCPP_VERBOSE_ABORT("length_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);243#endif244}245 246_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range(const char* __msg) {247#ifndef _LIBCPP_HAS_NO_EXCEPTIONS248 throw out_of_range(__msg);249#else250 _LIBCPP_VERBOSE_ABORT("out_of_range was thrown in -fno-exceptions mode with message \"%s\"", __msg);251#endif252}253 254_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_range_error(const char* __msg) {255#ifndef _LIBCPP_HAS_NO_EXCEPTIONS256 throw range_error(__msg);257#else258 _LIBCPP_VERBOSE_ABORT("range_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);259#endif260}261 262_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_overflow_error(const char* __msg) {263#ifndef _LIBCPP_HAS_NO_EXCEPTIONS264 throw overflow_error(__msg);265#else266 _LIBCPP_VERBOSE_ABORT("overflow_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);267#endif268}269 270_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_underflow_error(const char* __msg) {271#ifndef _LIBCPP_HAS_NO_EXCEPTIONS272 throw underflow_error(__msg);273#else274 _LIBCPP_VERBOSE_ABORT("underflow_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);275#endif276}277 278_LIBCPP_END_NAMESPACE_STD279 280#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)281# include <__cxx03/cstdlib>282# include <__cxx03/exception>283# include <__cxx03/iosfwd>284#endif285 286#endif // _LIBCPP___CXX03_STDEXCEPT287