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
47 #include <iosfwd> // for string forward decl
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
60 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 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_EXCEPTION_ABI logic_error
79 #ifndef _LIBCPP_ABI_VCRUNTIME
81 _VSTD::__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 virtual ~logic_error() _NOEXCEPT;
91 virtual const char* what() const _NOEXCEPT;
94 explicit logic_error(const _VSTD::string&); // Symbol uses versioned std::string
95 _LIBCPP_INLINE_VISIBILITY explicit logic_error(const char* __s) : exception(__s) {}
99 class _LIBCPP_EXCEPTION_ABI runtime_error
102 #ifndef _LIBCPP_ABI_VCRUNTIME
104 _VSTD::__libcpp_refstring __imp_;
106 explicit runtime_error(const string&);
107 explicit runtime_error(const char*);
109 runtime_error(const runtime_error&) _NOEXCEPT;
110 runtime_error& operator=(const runtime_error&) _NOEXCEPT;
112 virtual ~runtime_error() _NOEXCEPT;
114 virtual const char* what() const _NOEXCEPT;
117 explicit runtime_error(const _VSTD::string&); // Symbol uses versioned std::string
118 _LIBCPP_INLINE_VISIBILITY explicit runtime_error(const char* __s) : exception(__s) {}
119 #endif // _LIBCPP_ABI_VCRUNTIME
122 class _LIBCPP_EXCEPTION_ABI domain_error
126 _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {}
127 _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {}
129 #ifndef _LIBCPP_ABI_VCRUNTIME
130 domain_error(const domain_error&) _NOEXCEPT = default;
131 virtual ~domain_error() _NOEXCEPT;
135 class _LIBCPP_EXCEPTION_ABI invalid_argument
139 _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {}
140 _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {}
142 #ifndef _LIBCPP_ABI_VCRUNTIME
143 invalid_argument(const invalid_argument&) _NOEXCEPT = default;
144 virtual ~invalid_argument() _NOEXCEPT;
148 class _LIBCPP_EXCEPTION_ABI length_error
152 _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {}
153 _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {}
154 #ifndef _LIBCPP_ABI_VCRUNTIME
155 length_error(const length_error&) _NOEXCEPT = default;
156 virtual ~length_error() _NOEXCEPT;
160 class _LIBCPP_EXCEPTION_ABI out_of_range
164 _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {}
165 _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {}
167 #ifndef _LIBCPP_ABI_VCRUNTIME
168 out_of_range(const out_of_range&) _NOEXCEPT = default;
169 virtual ~out_of_range() _NOEXCEPT;
173 class _LIBCPP_EXCEPTION_ABI range_error
174 : public runtime_error
177 _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {}
178 _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {}
180 #ifndef _LIBCPP_ABI_VCRUNTIME
181 range_error(const range_error&) _NOEXCEPT = default;
182 virtual ~range_error() _NOEXCEPT;
186 class _LIBCPP_EXCEPTION_ABI overflow_error
187 : public runtime_error
190 _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {}
191 _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {}
193 #ifndef _LIBCPP_ABI_VCRUNTIME
194 overflow_error(const overflow_error&) _NOEXCEPT = default;
195 virtual ~overflow_error() _NOEXCEPT;
199 class _LIBCPP_EXCEPTION_ABI underflow_error
200 : public runtime_error
203 _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {}
204 _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {}
206 #ifndef _LIBCPP_ABI_VCRUNTIME
207 underflow_error(const underflow_error&) _NOEXCEPT = default;
208 virtual ~underflow_error() _NOEXCEPT;
214 _LIBCPP_BEGIN_NAMESPACE_STD
217 _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
219 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
220 void __throw_logic_error(const char*__msg)
222 #ifndef _LIBCPP_NO_EXCEPTIONS
223 throw logic_error(__msg);
230 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
231 void __throw_domain_error(const char*__msg)
233 #ifndef _LIBCPP_NO_EXCEPTIONS
234 throw domain_error(__msg);
241 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
242 void __throw_invalid_argument(const char*__msg)
244 #ifndef _LIBCPP_NO_EXCEPTIONS
245 throw invalid_argument(__msg);
252 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
253 void __throw_length_error(const char*__msg)
255 #ifndef _LIBCPP_NO_EXCEPTIONS
256 throw length_error(__msg);
263 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
264 void __throw_out_of_range(const char*__msg)
266 #ifndef _LIBCPP_NO_EXCEPTIONS
267 throw out_of_range(__msg);
274 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
275 void __throw_range_error(const char*__msg)
277 #ifndef _LIBCPP_NO_EXCEPTIONS
278 throw range_error(__msg);
285 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
286 void __throw_overflow_error(const char*__msg)
288 #ifndef _LIBCPP_NO_EXCEPTIONS
289 throw overflow_error(__msg);
296 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
297 void __throw_underflow_error(const char*__msg)
299 #ifndef _LIBCPP_NO_EXCEPTIONS
300 throw underflow_error(__msg);
307 _LIBCPP_END_NAMESPACE_STD
309 #endif // _LIBCPP_STDEXCEPT