2 //===--------------------------- stdexcept --------------------------------===//
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
46 #include <iosfwd> // for string forward decl
47 #ifdef _LIBCPP_NO_EXCEPTIONS
51 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
52 #pragma GCC system_header
55 _LIBCPP_BEGIN_NAMESPACE_STD
57 #ifndef _LIBCPP_ABI_VCRUNTIME
58 class _LIBCPP_HIDDEN __libcpp_refstring
62 bool __uses_refcount() const;
64 explicit __libcpp_refstring(const char* __msg);
65 __libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT;
66 __libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT;
67 ~__libcpp_refstring();
69 const char* c_str() const _NOEXCEPT {return __imp_;}
71 #endif // !_LIBCPP_ABI_VCRUNTIME
73 _LIBCPP_END_NAMESPACE_STD
75 namespace std // purposefully not using versioning namespace
78 class _LIBCPP_EXCEPTION_ABI logic_error
81 #ifndef _LIBCPP_ABI_VCRUNTIME
83 _VSTD::__libcpp_refstring __imp_;
85 explicit logic_error(const string&);
86 explicit logic_error(const char*);
88 logic_error(const logic_error&) _NOEXCEPT;
89 logic_error& operator=(const logic_error&) _NOEXCEPT;
91 virtual ~logic_error() _NOEXCEPT;
93 virtual const char* what() const _NOEXCEPT;
96 explicit logic_error(const _VSTD::string&); // Symbol uses versioned std::string
97 _LIBCPP_INLINE_VISIBILITY explicit logic_error(const char* __s) : exception(__s) {}
101 class _LIBCPP_EXCEPTION_ABI runtime_error
104 #ifndef _LIBCPP_ABI_VCRUNTIME
106 _VSTD::__libcpp_refstring __imp_;
108 explicit runtime_error(const string&);
109 explicit runtime_error(const char*);
111 runtime_error(const runtime_error&) _NOEXCEPT;
112 runtime_error& operator=(const runtime_error&) _NOEXCEPT;
114 virtual ~runtime_error() _NOEXCEPT;
116 virtual const char* what() const _NOEXCEPT;
119 explicit runtime_error(const _VSTD::string&); // Symbol uses versioned std::string
120 _LIBCPP_INLINE_VISIBILITY explicit runtime_error(const char* __s) : exception(__s) {}
121 #endif // _LIBCPP_ABI_VCRUNTIME
124 class _LIBCPP_EXCEPTION_ABI domain_error
128 _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {}
129 _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {}
131 #ifndef _LIBCPP_ABI_VCRUNTIME
132 domain_error(const domain_error&) _NOEXCEPT = default;
133 virtual ~domain_error() _NOEXCEPT;
137 class _LIBCPP_EXCEPTION_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 invalid_argument(const invalid_argument&) _NOEXCEPT = default;
146 virtual ~invalid_argument() _NOEXCEPT;
150 class _LIBCPP_EXCEPTION_ABI length_error
154 _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {}
155 _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {}
156 #ifndef _LIBCPP_ABI_VCRUNTIME
157 length_error(const length_error&) _NOEXCEPT = default;
158 virtual ~length_error() _NOEXCEPT;
162 class _LIBCPP_EXCEPTION_ABI out_of_range
166 _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {}
167 _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {}
169 #ifndef _LIBCPP_ABI_VCRUNTIME
170 out_of_range(const out_of_range&) _NOEXCEPT = default;
171 virtual ~out_of_range() _NOEXCEPT;
175 class _LIBCPP_EXCEPTION_ABI range_error
176 : public runtime_error
179 _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {}
180 _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {}
182 #ifndef _LIBCPP_ABI_VCRUNTIME
183 range_error(const range_error&) _NOEXCEPT = default;
184 virtual ~range_error() _NOEXCEPT;
188 class _LIBCPP_EXCEPTION_ABI overflow_error
189 : public runtime_error
192 _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {}
193 _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {}
195 #ifndef _LIBCPP_ABI_VCRUNTIME
196 overflow_error(const overflow_error&) _NOEXCEPT = default;
197 virtual ~overflow_error() _NOEXCEPT;
201 class _LIBCPP_EXCEPTION_ABI underflow_error
202 : public runtime_error
205 _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {}
206 _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {}
208 #ifndef _LIBCPP_ABI_VCRUNTIME
209 underflow_error(const underflow_error&) _NOEXCEPT = default;
210 virtual ~underflow_error() _NOEXCEPT;
216 _LIBCPP_BEGIN_NAMESPACE_STD
219 _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
221 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
222 void __throw_logic_error(const char*__msg)
224 #ifndef _LIBCPP_NO_EXCEPTIONS
225 throw logic_error(__msg);
232 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
233 void __throw_domain_error(const char*__msg)
235 #ifndef _LIBCPP_NO_EXCEPTIONS
236 throw domain_error(__msg);
243 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
244 void __throw_invalid_argument(const char*__msg)
246 #ifndef _LIBCPP_NO_EXCEPTIONS
247 throw invalid_argument(__msg);
254 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
255 void __throw_length_error(const char*__msg)
257 #ifndef _LIBCPP_NO_EXCEPTIONS
258 throw length_error(__msg);
265 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
266 void __throw_out_of_range(const char*__msg)
268 #ifndef _LIBCPP_NO_EXCEPTIONS
269 throw out_of_range(__msg);
276 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
277 void __throw_range_error(const char*__msg)
279 #ifndef _LIBCPP_NO_EXCEPTIONS
280 throw range_error(__msg);
287 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
288 void __throw_overflow_error(const char*__msg)
290 #ifndef _LIBCPP_NO_EXCEPTIONS
291 throw overflow_error(__msg);
298 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
299 void __throw_underflow_error(const char*__msg)
301 #ifndef _LIBCPP_NO_EXCEPTIONS
302 throw underflow_error(__msg);
309 _LIBCPP_END_NAMESPACE_STD
311 #endif // _LIBCPP_STDEXCEPT