Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- stdexcept --------------------------------===// |
| 3 | // |
Howard Hinnant | c566dc3 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | ee11c31 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_STDEXCEPT |
| 12 | #define _LIBCPP_STDEXCEPT |
| 13 | |
| 14 | /* |
| 15 | stdexcept synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | class logic_error; |
| 21 | class domain_error; |
| 22 | class invalid_argument; |
| 23 | class length_error; |
| 24 | class out_of_range; |
| 25 | class runtime_error; |
| 26 | class range_error; |
| 27 | class overflow_error; |
| 28 | class underflow_error; |
| 29 | |
| 30 | for each class xxx_error: |
| 31 | |
| 32 | class xxx_error : public exception // at least indirectly |
| 33 | { |
| 34 | public: |
| 35 | explicit xxx_error(const string& what_arg); |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 36 | explicit xxx_error(const char* what_arg); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 37 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 38 | virtual const char* what() const noexcept // returns what_arg |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | } // std |
| 42 | |
| 43 | */ |
| 44 | |
| 45 | #include <__config> |
| 46 | #include <exception> |
| 47 | #include <iosfwd> // for string forward decl |
Eric Fiselier | 279c319 | 2016-09-06 21:25:27 +0000 | [diff] [blame] | 48 | #ifdef _LIBCPP_NO_EXCEPTIONS |
| 49 | #include <cstdlib> |
| 50 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 51 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 52 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 53 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 54 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 55 | |
Joerg Sonnenberger | a47c2e7 | 2014-04-30 19:54:11 +0000 | [diff] [blame] | 56 | _LIBCPP_BEGIN_NAMESPACE_STD |
Eric Fiselier | 1e65516 | 2016-10-25 19:33:14 +0000 | [diff] [blame] | 57 | |
| 58 | class _LIBCPP_HIDDEN __libcpp_refstring |
| 59 | { |
| 60 | const char* __imp_; |
| 61 | |
| 62 | bool __uses_refcount() const; |
| 63 | public: |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 64 | explicit __libcpp_refstring(const char* __msg); |
| 65 | __libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT; |
| 66 | __libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT; |
Eric Fiselier | 1e65516 | 2016-10-25 19:33:14 +0000 | [diff] [blame] | 67 | ~__libcpp_refstring(); |
| 68 | |
| 69 | const char* c_str() const _NOEXCEPT {return __imp_;} |
Joerg Sonnenberger | a47c2e7 | 2014-04-30 19:54:11 +0000 | [diff] [blame] | 70 | }; |
Eric Fiselier | 1e65516 | 2016-10-25 19:33:14 +0000 | [diff] [blame] | 71 | |
Joerg Sonnenberger | a47c2e7 | 2014-04-30 19:54:11 +0000 | [diff] [blame] | 72 | _LIBCPP_END_NAMESPACE_STD |
Joerg Sonnenberger | a47c2e7 | 2014-04-30 19:54:11 +0000 | [diff] [blame] | 73 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 74 | namespace std // purposefully not using versioning namespace |
| 75 | { |
| 76 | |
| 77 | class _LIBCPP_EXCEPTION_ABI logic_error |
| 78 | : public exception |
| 79 | { |
| 80 | private: |
Joerg Sonnenberger | a47c2e7 | 2014-04-30 19:54:11 +0000 | [diff] [blame] | 81 | _VSTD::__libcpp_refstring __imp_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 82 | public: |
| 83 | explicit logic_error(const string&); |
| 84 | explicit logic_error(const char*); |
| 85 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 86 | logic_error(const logic_error&) _NOEXCEPT; |
| 87 | logic_error& operator=(const logic_error&) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 88 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 89 | virtual ~logic_error() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 90 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 91 | virtual const char* what() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | class _LIBCPP_EXCEPTION_ABI runtime_error |
| 95 | : public exception |
| 96 | { |
| 97 | private: |
Joerg Sonnenberger | a47c2e7 | 2014-04-30 19:54:11 +0000 | [diff] [blame] | 98 | _VSTD::__libcpp_refstring __imp_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 99 | public: |
| 100 | explicit runtime_error(const string&); |
| 101 | explicit runtime_error(const char*); |
| 102 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 103 | runtime_error(const runtime_error&) _NOEXCEPT; |
| 104 | runtime_error& operator=(const runtime_error&) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 105 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 106 | virtual ~runtime_error() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 107 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 108 | virtual const char* what() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | class _LIBCPP_EXCEPTION_ABI domain_error |
| 112 | : public logic_error |
| 113 | { |
| 114 | public: |
| 115 | _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {} |
| 116 | _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {} |
| 117 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 118 | virtual ~domain_error() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | class _LIBCPP_EXCEPTION_ABI invalid_argument |
| 122 | : public logic_error |
| 123 | { |
| 124 | public: |
| 125 | _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {} |
| 126 | _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {} |
| 127 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 128 | virtual ~invalid_argument() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | class _LIBCPP_EXCEPTION_ABI length_error |
| 132 | : public logic_error |
| 133 | { |
| 134 | public: |
| 135 | _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {} |
| 136 | _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {} |
| 137 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 138 | virtual ~length_error() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | class _LIBCPP_EXCEPTION_ABI out_of_range |
| 142 | : public logic_error |
| 143 | { |
| 144 | public: |
| 145 | _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {} |
| 146 | _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {} |
| 147 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 148 | virtual ~out_of_range() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | class _LIBCPP_EXCEPTION_ABI range_error |
| 152 | : public runtime_error |
| 153 | { |
| 154 | public: |
| 155 | _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {} |
| 156 | _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {} |
| 157 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 158 | virtual ~range_error() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | class _LIBCPP_EXCEPTION_ABI overflow_error |
| 162 | : public runtime_error |
| 163 | { |
| 164 | public: |
| 165 | _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {} |
| 166 | _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {} |
| 167 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 168 | virtual ~overflow_error() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | class _LIBCPP_EXCEPTION_ABI underflow_error |
| 172 | : public runtime_error |
| 173 | { |
| 174 | public: |
| 175 | _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {} |
| 176 | _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {} |
| 177 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 178 | virtual ~underflow_error() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 179 | }; |
| 180 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 181 | } // std |
| 182 | |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 183 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 184 | |
| 185 | // in the dylib |
| 186 | _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*); |
| 187 | |
Louis Dionne | 9dc6724 | 2018-07-05 16:49:38 +0000 | [diff] [blame] | 188 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 189 | void __throw_logic_error(const char*__msg) |
| 190 | { |
| 191 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 192 | throw logic_error(__msg); |
| 193 | #else |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 194 | ((void)__msg); |
| 195 | _VSTD::abort(); |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 196 | #endif |
| 197 | } |
| 198 | |
Louis Dionne | 9dc6724 | 2018-07-05 16:49:38 +0000 | [diff] [blame] | 199 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 200 | void __throw_domain_error(const char*__msg) |
| 201 | { |
| 202 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 203 | throw domain_error(__msg); |
| 204 | #else |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 205 | ((void)__msg); |
| 206 | _VSTD::abort(); |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 207 | #endif |
| 208 | } |
| 209 | |
Louis Dionne | 9dc6724 | 2018-07-05 16:49:38 +0000 | [diff] [blame] | 210 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 211 | void __throw_invalid_argument(const char*__msg) |
| 212 | { |
| 213 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 214 | throw invalid_argument(__msg); |
| 215 | #else |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 216 | ((void)__msg); |
| 217 | _VSTD::abort(); |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 218 | #endif |
| 219 | } |
| 220 | |
Louis Dionne | 9dc6724 | 2018-07-05 16:49:38 +0000 | [diff] [blame] | 221 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 222 | void __throw_length_error(const char*__msg) |
| 223 | { |
| 224 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 225 | throw length_error(__msg); |
| 226 | #else |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 227 | ((void)__msg); |
| 228 | _VSTD::abort(); |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 229 | #endif |
| 230 | } |
| 231 | |
Louis Dionne | 9dc6724 | 2018-07-05 16:49:38 +0000 | [diff] [blame] | 232 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 233 | void __throw_out_of_range(const char*__msg) |
| 234 | { |
| 235 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 236 | throw out_of_range(__msg); |
| 237 | #else |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 238 | ((void)__msg); |
| 239 | _VSTD::abort(); |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 240 | #endif |
| 241 | } |
| 242 | |
Louis Dionne | 9dc6724 | 2018-07-05 16:49:38 +0000 | [diff] [blame] | 243 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 244 | void __throw_range_error(const char*__msg) |
| 245 | { |
| 246 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 247 | throw range_error(__msg); |
| 248 | #else |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 249 | ((void)__msg); |
| 250 | _VSTD::abort(); |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 251 | #endif |
| 252 | } |
| 253 | |
Louis Dionne | 9dc6724 | 2018-07-05 16:49:38 +0000 | [diff] [blame] | 254 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 255 | void __throw_overflow_error(const char*__msg) |
| 256 | { |
| 257 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 258 | throw overflow_error(__msg); |
| 259 | #else |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 260 | ((void)__msg); |
| 261 | _VSTD::abort(); |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 262 | #endif |
| 263 | } |
| 264 | |
Louis Dionne | 9dc6724 | 2018-07-05 16:49:38 +0000 | [diff] [blame] | 265 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 266 | void __throw_underflow_error(const char*__msg) |
| 267 | { |
| 268 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 269 | throw underflow_error(__msg); |
| 270 | #else |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 271 | ((void)__msg); |
| 272 | _VSTD::abort(); |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 273 | #endif |
| 274 | } |
| 275 | |
| 276 | _LIBCPP_END_NAMESPACE_STD |
| 277 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 278 | #endif // _LIBCPP_STDEXCEPT |