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 | #ifndef _LIBCPP___REFSTRING |
| 57 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 58 | class _LIBCPP_HIDDEN __libcpp_refstring { |
Eric Fiselier | 6585c75 | 2016-04-21 22:54:21 +0000 | [diff] [blame] | 59 | #ifdef __clang__ |
| 60 | const char *__imp_ __attribute__((__unused__)); // only clang emits a warning |
| 61 | #else |
| 62 | const char *__imp_; |
| 63 | #endif |
Joerg Sonnenberger | a47c2e7 | 2014-04-30 19:54:11 +0000 | [diff] [blame] | 64 | }; |
| 65 | _LIBCPP_END_NAMESPACE_STD |
| 66 | #endif |
| 67 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 68 | namespace std // purposefully not using versioning namespace |
| 69 | { |
| 70 | |
| 71 | class _LIBCPP_EXCEPTION_ABI logic_error |
| 72 | : public exception |
| 73 | { |
| 74 | private: |
Joerg Sonnenberger | a47c2e7 | 2014-04-30 19:54:11 +0000 | [diff] [blame] | 75 | _VSTD::__libcpp_refstring __imp_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 76 | public: |
| 77 | explicit logic_error(const string&); |
| 78 | explicit logic_error(const char*); |
| 79 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 80 | logic_error(const logic_error&) _NOEXCEPT; |
| 81 | logic_error& operator=(const logic_error&) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 82 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 83 | virtual ~logic_error() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 84 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 85 | virtual const char* what() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | class _LIBCPP_EXCEPTION_ABI runtime_error |
| 89 | : public exception |
| 90 | { |
| 91 | private: |
Joerg Sonnenberger | a47c2e7 | 2014-04-30 19:54:11 +0000 | [diff] [blame] | 92 | _VSTD::__libcpp_refstring __imp_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 93 | public: |
| 94 | explicit runtime_error(const string&); |
| 95 | explicit runtime_error(const char*); |
| 96 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 97 | runtime_error(const runtime_error&) _NOEXCEPT; |
| 98 | runtime_error& operator=(const runtime_error&) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 99 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 100 | virtual ~runtime_error() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 101 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 102 | virtual const char* what() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | class _LIBCPP_EXCEPTION_ABI domain_error |
| 106 | : public logic_error |
| 107 | { |
| 108 | public: |
| 109 | _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {} |
| 110 | _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {} |
| 111 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 112 | virtual ~domain_error() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | class _LIBCPP_EXCEPTION_ABI invalid_argument |
| 116 | : public logic_error |
| 117 | { |
| 118 | public: |
| 119 | _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {} |
| 120 | _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {} |
| 121 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 122 | virtual ~invalid_argument() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | class _LIBCPP_EXCEPTION_ABI length_error |
| 126 | : public logic_error |
| 127 | { |
| 128 | public: |
| 129 | _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {} |
| 130 | _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {} |
| 131 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 132 | virtual ~length_error() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | class _LIBCPP_EXCEPTION_ABI out_of_range |
| 136 | : public logic_error |
| 137 | { |
| 138 | public: |
| 139 | _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {} |
| 140 | _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {} |
| 141 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 142 | virtual ~out_of_range() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | class _LIBCPP_EXCEPTION_ABI range_error |
| 146 | : public runtime_error |
| 147 | { |
| 148 | public: |
| 149 | _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {} |
| 150 | _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {} |
| 151 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 152 | virtual ~range_error() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | class _LIBCPP_EXCEPTION_ABI overflow_error |
| 156 | : public runtime_error |
| 157 | { |
| 158 | public: |
| 159 | _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {} |
| 160 | _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {} |
| 161 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 162 | virtual ~overflow_error() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | class _LIBCPP_EXCEPTION_ABI underflow_error |
| 166 | : public runtime_error |
| 167 | { |
| 168 | public: |
| 169 | _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {} |
| 170 | _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {} |
| 171 | |
Howard Hinnant | 1f098bc | 2011-05-26 19:48:01 +0000 | [diff] [blame] | 172 | virtual ~underflow_error() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 173 | }; |
| 174 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 175 | } // std |
| 176 | |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 177 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 178 | |
| 179 | // in the dylib |
| 180 | _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*); |
| 181 | |
| 182 | _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE |
| 183 | void __throw_logic_error(const char*__msg) |
| 184 | { |
| 185 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 186 | throw logic_error(__msg); |
| 187 | #else |
| 188 | _VSTD::abort(); |
| 189 | #endif |
| 190 | } |
| 191 | |
| 192 | _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE |
| 193 | void __throw_domain_error(const char*__msg) |
| 194 | { |
| 195 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 196 | throw domain_error(__msg); |
| 197 | #else |
| 198 | _VSTD::abort(); |
| 199 | #endif |
| 200 | } |
| 201 | |
| 202 | _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE |
| 203 | void __throw_invalid_argument(const char*__msg) |
| 204 | { |
| 205 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 206 | throw invalid_argument(__msg); |
| 207 | #else |
| 208 | _VSTD::abort(); |
| 209 | #endif |
| 210 | } |
| 211 | |
| 212 | _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE |
| 213 | void __throw_length_error(const char*__msg) |
| 214 | { |
| 215 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 216 | throw length_error(__msg); |
| 217 | #else |
| 218 | _VSTD::abort(); |
| 219 | #endif |
| 220 | } |
| 221 | |
| 222 | _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE |
| 223 | void __throw_out_of_range(const char*__msg) |
| 224 | { |
| 225 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 226 | throw out_of_range(__msg); |
| 227 | #else |
| 228 | _VSTD::abort(); |
| 229 | #endif |
| 230 | } |
| 231 | |
| 232 | _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE |
| 233 | void __throw_range_error(const char*__msg) |
| 234 | { |
| 235 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 236 | throw range_error(__msg); |
| 237 | #else |
| 238 | _VSTD::abort(); |
| 239 | #endif |
| 240 | } |
| 241 | |
| 242 | _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE |
| 243 | void __throw_overflow_error(const char*__msg) |
| 244 | { |
| 245 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 246 | throw overflow_error(__msg); |
| 247 | #else |
| 248 | _VSTD::abort(); |
| 249 | #endif |
| 250 | } |
| 251 | |
| 252 | _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE |
| 253 | void __throw_underflow_error(const char*__msg) |
| 254 | { |
| 255 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 256 | throw underflow_error(__msg); |
| 257 | #else |
| 258 | _VSTD::abort(); |
| 259 | #endif |
| 260 | } |
| 261 | |
| 262 | _LIBCPP_END_NAMESPACE_STD |
| 263 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 264 | #endif // _LIBCPP_STDEXCEPT |