2 //===----------------------------------------------------------------------===//
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-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_STDEXCEPT
11 #define _LIBCPP_STDEXCEPT
21 class invalid_argument;
27 class underflow_error;
29 for each class xxx_error:
31 class xxx_error : public exception // at least indirectly
34 explicit xxx_error(const string& what_arg);
35 explicit xxx_error(const char* what_arg);
37 virtual const char* what() const noexcept // returns what_arg
44 #include <__assert> // all public C++ headers provide the assertion handler
46 #include <__exception/exception.h>
47 #include <__fwd/string.h>
48 #include <__verbose_abort>
50 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
51 # pragma GCC system_header
54 _LIBCPP_BEGIN_NAMESPACE_STD
56 #ifndef _LIBCPP_ABI_VCRUNTIME
57 class _LIBCPP_HIDDEN __libcpp_refstring
61 bool __uses_refcount() const;
63 explicit __libcpp_refstring(const char* __msg);
64 __libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT;
65 __libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT;
66 ~__libcpp_refstring();
68 _LIBCPP_HIDE_FROM_ABI const char* c_str() const _NOEXCEPT {return __imp_;}
70 #endif // !_LIBCPP_ABI_VCRUNTIME
72 _LIBCPP_END_NAMESPACE_STD
74 namespace std // purposefully not using versioning namespace
77 class _LIBCPP_EXPORTED_FROM_ABI logic_error
80 #ifndef _LIBCPP_ABI_VCRUNTIME
82 _VSTD::__libcpp_refstring __imp_;
84 explicit logic_error(const string&);
85 explicit logic_error(const char*);
87 logic_error(const logic_error&) _NOEXCEPT;
88 logic_error& operator=(const logic_error&) _NOEXCEPT;
90 ~logic_error() _NOEXCEPT override;
92 const char* what() const _NOEXCEPT override;
95 explicit logic_error(const _VSTD::string&); // Symbol uses versioned std::string
96 _LIBCPP_INLINE_VISIBILITY explicit logic_error(const char* __s) : exception(__s) {}
100 class _LIBCPP_EXPORTED_FROM_ABI runtime_error
103 #ifndef _LIBCPP_ABI_VCRUNTIME
105 _VSTD::__libcpp_refstring __imp_;
107 explicit runtime_error(const string&);
108 explicit runtime_error(const char*);
110 runtime_error(const runtime_error&) _NOEXCEPT;
111 runtime_error& operator=(const runtime_error&) _NOEXCEPT;
113 ~runtime_error() _NOEXCEPT override;
115 const char* what() const _NOEXCEPT override;
118 explicit runtime_error(const _VSTD::string&); // Symbol uses versioned std::string
119 _LIBCPP_INLINE_VISIBILITY explicit runtime_error(const char* __s) : exception(__s) {}
120 #endif // _LIBCPP_ABI_VCRUNTIME
123 class _LIBCPP_EXPORTED_FROM_ABI domain_error
127 _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {}
128 _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {}
130 #ifndef _LIBCPP_ABI_VCRUNTIME
131 _LIBCPP_HIDE_FROM_ABI domain_error(const domain_error&) _NOEXCEPT = default;
132 _LIBCPP_HIDE_FROM_ABI domain_error& operator=(const domain_error&) _NOEXCEPT = default;
133 ~domain_error() _NOEXCEPT override;
137 class _LIBCPP_EXPORTED_FROM_ABI invalid_argument
141 _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {}
142 _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {}
144 #ifndef _LIBCPP_ABI_VCRUNTIME
145 _LIBCPP_HIDE_FROM_ABI invalid_argument(const invalid_argument&) _NOEXCEPT = default;
146 _LIBCPP_HIDE_FROM_ABI invalid_argument& operator=(const invalid_argument&) _NOEXCEPT = default;
147 ~invalid_argument() _NOEXCEPT override;
151 class _LIBCPP_EXPORTED_FROM_ABI length_error
155 _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {}
156 _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {}
157 #ifndef _LIBCPP_ABI_VCRUNTIME
158 _LIBCPP_HIDE_FROM_ABI length_error(const length_error&) _NOEXCEPT = default;
159 _LIBCPP_HIDE_FROM_ABI length_error& operator=(const length_error&) _NOEXCEPT = default;
160 ~length_error() _NOEXCEPT override;
164 class _LIBCPP_EXPORTED_FROM_ABI out_of_range
168 _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {}
169 _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {}
171 #ifndef _LIBCPP_ABI_VCRUNTIME
172 _LIBCPP_HIDE_FROM_ABI out_of_range(const out_of_range&) _NOEXCEPT = default;
173 _LIBCPP_HIDE_FROM_ABI out_of_range& operator=(const out_of_range&) _NOEXCEPT = default;
174 ~out_of_range() _NOEXCEPT override;
178 class _LIBCPP_EXPORTED_FROM_ABI range_error
179 : public runtime_error
182 _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {}
183 _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {}
185 #ifndef _LIBCPP_ABI_VCRUNTIME
186 _LIBCPP_HIDE_FROM_ABI range_error(const range_error&) _NOEXCEPT = default;
187 _LIBCPP_HIDE_FROM_ABI range_error& operator=(const range_error&) _NOEXCEPT = default;
188 ~range_error() _NOEXCEPT override;
192 class _LIBCPP_EXPORTED_FROM_ABI overflow_error
193 : public runtime_error
196 _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {}
197 _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {}
199 #ifndef _LIBCPP_ABI_VCRUNTIME
200 _LIBCPP_HIDE_FROM_ABI overflow_error(const overflow_error&) _NOEXCEPT = default;
201 _LIBCPP_HIDE_FROM_ABI overflow_error& operator=(const overflow_error&) _NOEXCEPT = default;
202 ~overflow_error() _NOEXCEPT override;
206 class _LIBCPP_EXPORTED_FROM_ABI underflow_error
207 : public runtime_error
210 _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {}
211 _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {}
213 #ifndef _LIBCPP_ABI_VCRUNTIME
214 _LIBCPP_HIDE_FROM_ABI underflow_error(const underflow_error&) _NOEXCEPT = default;
215 _LIBCPP_HIDE_FROM_ABI underflow_error& operator=(const underflow_error&) _NOEXCEPT = default;
216 ~underflow_error() _NOEXCEPT override;
222 _LIBCPP_BEGIN_NAMESPACE_STD
225 _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_runtime_error(const char*);
227 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
228 void __throw_logic_error(const char*__msg)
230 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
231 throw logic_error(__msg);
233 _LIBCPP_VERBOSE_ABORT("logic_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
237 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
238 void __throw_domain_error(const char*__msg)
240 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
241 throw domain_error(__msg);
243 _LIBCPP_VERBOSE_ABORT("domain_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
247 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
248 void __throw_invalid_argument(const char*__msg)
250 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
251 throw invalid_argument(__msg);
253 _LIBCPP_VERBOSE_ABORT("invalid_argument was thrown in -fno-exceptions mode with message \"%s\"", __msg);
257 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
258 void __throw_length_error(const char*__msg)
260 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
261 throw length_error(__msg);
263 _LIBCPP_VERBOSE_ABORT("length_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
267 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
268 void __throw_out_of_range(const char*__msg)
270 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
271 throw out_of_range(__msg);
273 _LIBCPP_VERBOSE_ABORT("out_of_range was thrown in -fno-exceptions mode with message \"%s\"", __msg);
277 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
278 void __throw_range_error(const char*__msg)
280 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
281 throw range_error(__msg);
283 _LIBCPP_VERBOSE_ABORT("range_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
287 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
288 void __throw_overflow_error(const char*__msg)
290 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
291 throw overflow_error(__msg);
293 _LIBCPP_VERBOSE_ABORT("overflow_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
297 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
298 void __throw_underflow_error(const char*__msg)
300 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
301 throw underflow_error(__msg);
303 _LIBCPP_VERBOSE_ABORT("underflow_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
307 _LIBCPP_END_NAMESPACE_STD
309 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
311 # include <exception>
315 #endif // _LIBCPP_STDEXCEPT