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 #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
45 # include <__cxx03/stdexcept>
48 # include <__exception/exception.h>
49 # include <__fwd/string.h>
50 # include <__verbose_abort>
52 # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
53 # pragma GCC system_header
56 _LIBCPP_BEGIN_NAMESPACE_STD
58 # ifndef _LIBCPP_ABI_VCRUNTIME
59 class _LIBCPP_HIDDEN __libcpp_refstring {
62 bool __uses_refcount() const;
65 explicit __libcpp_refstring(const char* __msg);
66 __libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT;
67 __libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT;
68 ~__libcpp_refstring();
70 _LIBCPP_HIDE_FROM_ABI const char* c_str() const _NOEXCEPT { return __imp_; }
72 # endif // !_LIBCPP_ABI_VCRUNTIME
74 _LIBCPP_END_NAMESPACE_STD
76 namespace std // purposefully not using versioning namespace
79 class _LIBCPP_EXPORTED_FROM_ABI logic_error : public exception {
80 # ifndef _LIBCPP_ABI_VCRUNTIME
83 std::__libcpp_refstring __imp_;
86 explicit logic_error(const string&);
87 explicit logic_error(const char*);
89 logic_error(const logic_error&) _NOEXCEPT;
90 logic_error& operator=(const logic_error&) _NOEXCEPT;
92 ~logic_error() _NOEXCEPT override;
94 const char* what() const _NOEXCEPT override;
98 explicit logic_error(const std::string&); // Symbol uses versioned std::string
99 _LIBCPP_HIDE_FROM_ABI explicit logic_error(const char* __s) : exception(__s) {}
103 class _LIBCPP_EXPORTED_FROM_ABI runtime_error : public exception {
104 # ifndef _LIBCPP_ABI_VCRUNTIME
107 std::__libcpp_refstring __imp_;
110 explicit runtime_error(const string&);
111 explicit runtime_error(const char*);
113 runtime_error(const runtime_error&) _NOEXCEPT;
114 runtime_error& operator=(const runtime_error&) _NOEXCEPT;
116 ~runtime_error() _NOEXCEPT override;
118 const char* what() const _NOEXCEPT override;
122 explicit runtime_error(const std::string&); // Symbol uses versioned std::string
123 _LIBCPP_HIDE_FROM_ABI explicit runtime_error(const char* __s) : exception(__s) {}
124 # endif // _LIBCPP_ABI_VCRUNTIME
127 class _LIBCPP_EXPORTED_FROM_ABI domain_error : public logic_error {
129 _LIBCPP_HIDE_FROM_ABI explicit domain_error(const string& __s) : logic_error(__s) {}
130 _LIBCPP_HIDE_FROM_ABI explicit domain_error(const char* __s) : logic_error(__s) {}
132 # ifndef _LIBCPP_ABI_VCRUNTIME
133 _LIBCPP_HIDE_FROM_ABI domain_error(const domain_error&) _NOEXCEPT = default;
134 _LIBCPP_HIDE_FROM_ABI domain_error& operator=(const domain_error&) _NOEXCEPT = default;
135 ~domain_error() _NOEXCEPT override;
139 class _LIBCPP_EXPORTED_FROM_ABI invalid_argument : public logic_error {
141 _LIBCPP_HIDE_FROM_ABI explicit invalid_argument(const string& __s) : logic_error(__s) {}
142 _LIBCPP_HIDE_FROM_ABI 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 : public logic_error {
153 _LIBCPP_HIDE_FROM_ABI explicit length_error(const string& __s) : logic_error(__s) {}
154 _LIBCPP_HIDE_FROM_ABI explicit length_error(const char* __s) : logic_error(__s) {}
155 # ifndef _LIBCPP_ABI_VCRUNTIME
156 _LIBCPP_HIDE_FROM_ABI length_error(const length_error&) _NOEXCEPT = default;
157 _LIBCPP_HIDE_FROM_ABI length_error& operator=(const length_error&) _NOEXCEPT = default;
158 ~length_error() _NOEXCEPT override;
162 class _LIBCPP_EXPORTED_FROM_ABI out_of_range : public logic_error {
164 _LIBCPP_HIDE_FROM_ABI explicit out_of_range(const string& __s) : logic_error(__s) {}
165 _LIBCPP_HIDE_FROM_ABI explicit out_of_range(const char* __s) : logic_error(__s) {}
167 # ifndef _LIBCPP_ABI_VCRUNTIME
168 _LIBCPP_HIDE_FROM_ABI out_of_range(const out_of_range&) _NOEXCEPT = default;
169 _LIBCPP_HIDE_FROM_ABI out_of_range& operator=(const out_of_range&) _NOEXCEPT = default;
170 ~out_of_range() _NOEXCEPT override;
174 class _LIBCPP_EXPORTED_FROM_ABI range_error : public runtime_error {
176 _LIBCPP_HIDE_FROM_ABI explicit range_error(const string& __s) : runtime_error(__s) {}
177 _LIBCPP_HIDE_FROM_ABI explicit range_error(const char* __s) : runtime_error(__s) {}
179 # ifndef _LIBCPP_ABI_VCRUNTIME
180 _LIBCPP_HIDE_FROM_ABI range_error(const range_error&) _NOEXCEPT = default;
181 _LIBCPP_HIDE_FROM_ABI range_error& operator=(const range_error&) _NOEXCEPT = default;
182 ~range_error() _NOEXCEPT override;
186 class _LIBCPP_EXPORTED_FROM_ABI overflow_error : public runtime_error {
188 _LIBCPP_HIDE_FROM_ABI explicit overflow_error(const string& __s) : runtime_error(__s) {}
189 _LIBCPP_HIDE_FROM_ABI explicit overflow_error(const char* __s) : runtime_error(__s) {}
191 # ifndef _LIBCPP_ABI_VCRUNTIME
192 _LIBCPP_HIDE_FROM_ABI overflow_error(const overflow_error&) _NOEXCEPT = default;
193 _LIBCPP_HIDE_FROM_ABI overflow_error& operator=(const overflow_error&) _NOEXCEPT = default;
194 ~overflow_error() _NOEXCEPT override;
198 class _LIBCPP_EXPORTED_FROM_ABI underflow_error : public runtime_error {
200 _LIBCPP_HIDE_FROM_ABI explicit underflow_error(const string& __s) : runtime_error(__s) {}
201 _LIBCPP_HIDE_FROM_ABI explicit underflow_error(const char* __s) : runtime_error(__s) {}
203 # ifndef _LIBCPP_ABI_VCRUNTIME
204 _LIBCPP_HIDE_FROM_ABI underflow_error(const underflow_error&) _NOEXCEPT = default;
205 _LIBCPP_HIDE_FROM_ABI underflow_error& operator=(const underflow_error&) _NOEXCEPT = default;
206 ~underflow_error() _NOEXCEPT override;
212 _LIBCPP_BEGIN_NAMESPACE_STD
215 [[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_runtime_error(const char*);
217 [[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_logic_error(const char* __msg) {
218 # if _LIBCPP_HAS_EXCEPTIONS
219 throw logic_error(__msg);
221 _LIBCPP_VERBOSE_ABORT("logic_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
225 [[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_domain_error(const char* __msg) {
226 # if _LIBCPP_HAS_EXCEPTIONS
227 throw domain_error(__msg);
229 _LIBCPP_VERBOSE_ABORT("domain_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
233 [[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_invalid_argument(const char* __msg) {
234 # if _LIBCPP_HAS_EXCEPTIONS
235 throw invalid_argument(__msg);
237 _LIBCPP_VERBOSE_ABORT("invalid_argument was thrown in -fno-exceptions mode with message \"%s\"", __msg);
241 [[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_length_error(const char* __msg) {
242 # if _LIBCPP_HAS_EXCEPTIONS
243 throw length_error(__msg);
245 _LIBCPP_VERBOSE_ABORT("length_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
249 [[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range(const char* __msg) {
250 # if _LIBCPP_HAS_EXCEPTIONS
251 throw out_of_range(__msg);
253 _LIBCPP_VERBOSE_ABORT("out_of_range was thrown in -fno-exceptions mode with message \"%s\"", __msg);
257 [[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_range_error(const char* __msg) {
258 # if _LIBCPP_HAS_EXCEPTIONS
259 throw range_error(__msg);
261 _LIBCPP_VERBOSE_ABORT("range_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
265 [[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_overflow_error(const char* __msg) {
266 # if _LIBCPP_HAS_EXCEPTIONS
267 throw overflow_error(__msg);
269 _LIBCPP_VERBOSE_ABORT("overflow_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
273 [[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_underflow_error(const char* __msg) {
274 # if _LIBCPP_HAS_EXCEPTIONS
275 throw underflow_error(__msg);
277 _LIBCPP_VERBOSE_ABORT("underflow_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
281 _LIBCPP_END_NAMESPACE_STD
283 # if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
286 # include <exception>
290 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
292 #endif // _LIBCPP_STDEXCEPT