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___CXX03_STDEXCEPT
11 #define _LIBCPP___CXX03_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 <__cxx03/__config>
45 #include <__cxx03/__exception/exception.h>
46 #include <__cxx03/__fwd/string.h>
47 #include <__cxx03/__verbose_abort>
49 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
50 # pragma GCC system_header
53 _LIBCPP_BEGIN_NAMESPACE_STD
55 #ifndef _LIBCPP_ABI_VCRUNTIME
56 class _LIBCPP_HIDDEN __libcpp_refstring {
59 bool __uses_refcount() const;
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();
67 _LIBCPP_HIDE_FROM_ABI const char* c_str() const _NOEXCEPT { return __imp_; }
69 #endif // !_LIBCPP_ABI_VCRUNTIME
71 _LIBCPP_END_NAMESPACE_STD
73 namespace std // purposefully not using versioning namespace
76 class _LIBCPP_EXPORTED_FROM_ABI logic_error : public exception {
77 #ifndef _LIBCPP_ABI_VCRUNTIME
80 std::__libcpp_refstring __imp_;
83 explicit logic_error(const string&);
84 explicit logic_error(const char*);
86 logic_error(const logic_error&) _NOEXCEPT;
87 logic_error& operator=(const logic_error&) _NOEXCEPT;
89 ~logic_error() _NOEXCEPT override;
91 const char* what() const _NOEXCEPT override;
95 explicit logic_error(const std::string&); // Symbol uses versioned std::string
96 _LIBCPP_HIDE_FROM_ABI explicit logic_error(const char* __s) : exception(__s) {}
100 class _LIBCPP_EXPORTED_FROM_ABI runtime_error : public exception {
101 #ifndef _LIBCPP_ABI_VCRUNTIME
104 std::__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;
119 explicit runtime_error(const std::string&); // Symbol uses versioned std::string
120 _LIBCPP_HIDE_FROM_ABI explicit runtime_error(const char* __s) : exception(__s) {}
121 #endif // _LIBCPP_ABI_VCRUNTIME
124 class _LIBCPP_EXPORTED_FROM_ABI domain_error : public logic_error {
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) {}
129 #ifndef _LIBCPP_ABI_VCRUNTIME
130 _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;
136 class _LIBCPP_EXPORTED_FROM_ABI invalid_argument : public logic_error {
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) {}
141 #ifndef _LIBCPP_ABI_VCRUNTIME
142 _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;
148 class _LIBCPP_EXPORTED_FROM_ABI length_error : public logic_error {
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_VCRUNTIME
153 _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;
159 class _LIBCPP_EXPORTED_FROM_ABI out_of_range : public logic_error {
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) {}
164 #ifndef _LIBCPP_ABI_VCRUNTIME
165 _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;
171 class _LIBCPP_EXPORTED_FROM_ABI range_error : public runtime_error {
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) {}
176 #ifndef _LIBCPP_ABI_VCRUNTIME
177 _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;
183 class _LIBCPP_EXPORTED_FROM_ABI overflow_error : public runtime_error {
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) {}
188 #ifndef _LIBCPP_ABI_VCRUNTIME
189 _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;
195 class _LIBCPP_EXPORTED_FROM_ABI underflow_error : public runtime_error {
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) {}
200 #ifndef _LIBCPP_ABI_VCRUNTIME
201 _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;
209 _LIBCPP_BEGIN_NAMESPACE_STD
212 _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_runtime_error(const char*);
214 _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_logic_error(const char* __msg) {
215 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
216 throw logic_error(__msg);
218 _LIBCPP_VERBOSE_ABORT("logic_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
222 _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_domain_error(const char* __msg) {
223 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
224 throw domain_error(__msg);
226 _LIBCPP_VERBOSE_ABORT("domain_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
230 _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_invalid_argument(const char* __msg) {
231 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
232 throw invalid_argument(__msg);
234 _LIBCPP_VERBOSE_ABORT("invalid_argument was thrown in -fno-exceptions mode with message \"%s\"", __msg);
238 _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_length_error(const char* __msg) {
239 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
240 throw length_error(__msg);
242 _LIBCPP_VERBOSE_ABORT("length_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
246 _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range(const char* __msg) {
247 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
248 throw out_of_range(__msg);
250 _LIBCPP_VERBOSE_ABORT("out_of_range was thrown in -fno-exceptions mode with message \"%s\"", __msg);
254 _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_range_error(const char* __msg) {
255 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
256 throw range_error(__msg);
258 _LIBCPP_VERBOSE_ABORT("range_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
262 _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_overflow_error(const char* __msg) {
263 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
264 throw overflow_error(__msg);
266 _LIBCPP_VERBOSE_ABORT("overflow_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
270 _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_underflow_error(const char* __msg) {
271 #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
272 throw underflow_error(__msg);
274 _LIBCPP_VERBOSE_ABORT("underflow_error was thrown in -fno-exceptions mode with message \"%s\"", __msg);
278 _LIBCPP_END_NAMESPACE_STD
280 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
281 # include <__cxx03/cstdlib>
282 # include <__cxx03/exception>
283 # include <__cxx03/iosfwd>
286 #endif // _LIBCPP___CXX03_STDEXCEPT