2 //===--------------------------- stdexcept --------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_STDEXCEPT
12 #define _LIBCPP_STDEXCEPT
22 class invalid_argument;
28 class underflow_error;
30 for each class xxx_error:
32 class xxx_error : public exception // at least indirectly
35 explicit xxx_error(const string& what_arg);
36 explicit xxx_error(const char* what_arg);
38 virtual const char* what() const noexcept // returns what_arg
47 #include <iosfwd> // for string forward decl
48 #ifdef _LIBCPP_NO_EXCEPTIONS
52 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
53 #pragma GCC system_header
56 _LIBCPP_BEGIN_NAMESPACE_STD
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_;}
72 _LIBCPP_END_NAMESPACE_STD
74 namespace std // purposefully not using versioning namespace
77 class _LIBCPP_EXCEPTION_ABI logic_error
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 class _LIBCPP_EXCEPTION_ABI runtime_error
98 _VSTD::__libcpp_refstring __imp_;
100 explicit runtime_error(const string&);
101 explicit runtime_error(const char*);
103 runtime_error(const runtime_error&) _NOEXCEPT;
104 runtime_error& operator=(const runtime_error&) _NOEXCEPT;
106 virtual ~runtime_error() _NOEXCEPT;
108 virtual const char* what() const _NOEXCEPT;
111 class _LIBCPP_EXCEPTION_ABI domain_error
115 _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {}
116 _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {}
118 virtual ~domain_error() _NOEXCEPT;
121 class _LIBCPP_EXCEPTION_ABI invalid_argument
125 _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {}
126 _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {}
128 virtual ~invalid_argument() _NOEXCEPT;
131 class _LIBCPP_EXCEPTION_ABI length_error
135 _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {}
136 _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {}
138 virtual ~length_error() _NOEXCEPT;
141 class _LIBCPP_EXCEPTION_ABI out_of_range
145 _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {}
146 _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {}
148 virtual ~out_of_range() _NOEXCEPT;
151 class _LIBCPP_EXCEPTION_ABI range_error
152 : public runtime_error
155 _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {}
156 _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {}
158 virtual ~range_error() _NOEXCEPT;
161 class _LIBCPP_EXCEPTION_ABI overflow_error
162 : public runtime_error
165 _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {}
166 _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {}
168 virtual ~overflow_error() _NOEXCEPT;
171 class _LIBCPP_EXCEPTION_ABI underflow_error
172 : public runtime_error
175 _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {}
176 _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {}
178 virtual ~underflow_error() _NOEXCEPT;
183 _LIBCPP_BEGIN_NAMESPACE_STD
186 _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
188 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
189 void __throw_logic_error(const char*__msg)
191 #ifndef _LIBCPP_NO_EXCEPTIONS
192 throw logic_error(__msg);
199 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
200 void __throw_domain_error(const char*__msg)
202 #ifndef _LIBCPP_NO_EXCEPTIONS
203 throw domain_error(__msg);
210 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
211 void __throw_invalid_argument(const char*__msg)
213 #ifndef _LIBCPP_NO_EXCEPTIONS
214 throw invalid_argument(__msg);
221 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
222 void __throw_length_error(const char*__msg)
224 #ifndef _LIBCPP_NO_EXCEPTIONS
225 throw length_error(__msg);
232 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
233 void __throw_out_of_range(const char*__msg)
235 #ifndef _LIBCPP_NO_EXCEPTIONS
236 throw out_of_range(__msg);
243 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
244 void __throw_range_error(const char*__msg)
246 #ifndef _LIBCPP_NO_EXCEPTIONS
247 throw range_error(__msg);
254 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
255 void __throw_overflow_error(const char*__msg)
257 #ifndef _LIBCPP_NO_EXCEPTIONS
258 throw overflow_error(__msg);
265 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
266 void __throw_underflow_error(const char*__msg)
268 #ifndef _LIBCPP_NO_EXCEPTIONS
269 throw underflow_error(__msg);
276 _LIBCPP_END_NAMESPACE_STD
278 #endif // _LIBCPP_STDEXCEPT