blob: b9dd2853f28d254fff4a30d3d230a0a72d9bd74d [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===--------------------------- stdexcept --------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:168//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_STDEXCEPT
12#define _LIBCPP_STDEXCEPT
13
14/*
15 stdexcept synopsis
16
17namespace std
18{
19
20class logic_error;
21 class domain_error;
22 class invalid_argument;
23 class length_error;
24 class out_of_range;
25class runtime_error;
26 class range_error;
27 class overflow_error;
28 class underflow_error;
29
30for each class xxx_error:
31
32class xxx_error : public exception // at least indirectly
33{
34public:
35 explicit xxx_error(const string& what_arg);
Howard Hinnant1e15fd12011-05-26 19:48:0136 explicit xxx_error(const char* what_arg);
Howard Hinnantbc8d3f92010-05-11 19:42:1637
Howard Hinnant1e15fd12011-05-26 19:48:0138 virtual const char* what() const noexcept // returns what_arg
Howard Hinnantbc8d3f92010-05-11 19:42:1639};
40
41} // std
42
43*/
44
45#include <__config>
46#include <exception>
47#include <iosfwd> // for string forward decl
Eric Fiselierdbf60fa2016-09-06 21:25:2748#ifdef _LIBCPP_NO_EXCEPTIONS
49#include <cstdlib>
50#endif
Howard Hinnantbc8d3f92010-05-11 19:42:1651
Howard Hinnant08e17472011-10-17 20:05:1052#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:1653#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:1054#endif
Howard Hinnantbc8d3f92010-05-11 19:42:1655
Joerg Sonnenberger55622072014-04-30 19:54:1156_LIBCPP_BEGIN_NAMESPACE_STD
Eric Fiselier6979a422016-10-25 19:33:1457
58class _LIBCPP_HIDDEN __libcpp_refstring
59{
60 const char* __imp_;
61
62 bool __uses_refcount() const;
63public:
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();
68
69 const char* c_str() const _NOEXCEPT {return __imp_;}
Joerg Sonnenberger55622072014-04-30 19:54:1170};
Eric Fiselier6979a422016-10-25 19:33:1471
Joerg Sonnenberger55622072014-04-30 19:54:1172_LIBCPP_END_NAMESPACE_STD
Joerg Sonnenberger55622072014-04-30 19:54:1173
Howard Hinnantbc8d3f92010-05-11 19:42:1674namespace std // purposefully not using versioning namespace
75{
76
77class _LIBCPP_EXCEPTION_ABI logic_error
78 : public exception
79{
80private:
Joerg Sonnenberger55622072014-04-30 19:54:1181 _VSTD::__libcpp_refstring __imp_;
Howard Hinnantbc8d3f92010-05-11 19:42:1682public:
83 explicit logic_error(const string&);
84 explicit logic_error(const char*);
85
Howard Hinnant1e15fd12011-05-26 19:48:0186 logic_error(const logic_error&) _NOEXCEPT;
87 logic_error& operator=(const logic_error&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:1688
Howard Hinnant1e15fd12011-05-26 19:48:0189 virtual ~logic_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:1690
Howard Hinnant1e15fd12011-05-26 19:48:0191 virtual const char* what() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:1692};
93
94class _LIBCPP_EXCEPTION_ABI runtime_error
95 : public exception
96{
97private:
Joerg Sonnenberger55622072014-04-30 19:54:1198 _VSTD::__libcpp_refstring __imp_;
Howard Hinnantbc8d3f92010-05-11 19:42:1699public:
100 explicit runtime_error(const string&);
101 explicit runtime_error(const char*);
102
Howard Hinnant1e15fd12011-05-26 19:48:01103 runtime_error(const runtime_error&) _NOEXCEPT;
104 runtime_error& operator=(const runtime_error&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16105
Howard Hinnant1e15fd12011-05-26 19:48:01106 virtual ~runtime_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16107
Howard Hinnant1e15fd12011-05-26 19:48:01108 virtual const char* what() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16109};
110
111class _LIBCPP_EXCEPTION_ABI domain_error
112 : public logic_error
113{
114public:
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) {}
117
Howard Hinnant1e15fd12011-05-26 19:48:01118 virtual ~domain_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16119};
120
121class _LIBCPP_EXCEPTION_ABI invalid_argument
122 : public logic_error
123{
124public:
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) {}
127
Howard Hinnant1e15fd12011-05-26 19:48:01128 virtual ~invalid_argument() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16129};
130
131class _LIBCPP_EXCEPTION_ABI length_error
132 : public logic_error
133{
134public:
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) {}
137
Howard Hinnant1e15fd12011-05-26 19:48:01138 virtual ~length_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16139};
140
141class _LIBCPP_EXCEPTION_ABI out_of_range
142 : public logic_error
143{
144public:
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) {}
147
Howard Hinnant1e15fd12011-05-26 19:48:01148 virtual ~out_of_range() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16149};
150
151class _LIBCPP_EXCEPTION_ABI range_error
152 : public runtime_error
153{
154public:
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) {}
157
Howard Hinnant1e15fd12011-05-26 19:48:01158 virtual ~range_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16159};
160
161class _LIBCPP_EXCEPTION_ABI overflow_error
162 : public runtime_error
163{
164public:
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) {}
167
Howard Hinnant1e15fd12011-05-26 19:48:01168 virtual ~overflow_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16169};
170
171class _LIBCPP_EXCEPTION_ABI underflow_error
172 : public runtime_error
173{
174public:
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) {}
177
Howard Hinnant1e15fd12011-05-26 19:48:01178 virtual ~underflow_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16179};
180
Howard Hinnantbc8d3f92010-05-11 19:42:16181} // std
182
Marshall Clow14c09a22016-08-25 15:09:01183_LIBCPP_BEGIN_NAMESPACE_STD
184
185// in the dylib
186_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
187
188_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
189void __throw_logic_error(const char*__msg)
190{
191#ifndef _LIBCPP_NO_EXCEPTIONS
192 throw logic_error(__msg);
193#else
194_VSTD::abort();
195#endif
196}
197
198_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
199void __throw_domain_error(const char*__msg)
200{
201#ifndef _LIBCPP_NO_EXCEPTIONS
202 throw domain_error(__msg);
203#else
204_VSTD::abort();
205#endif
206}
207
208_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
209void __throw_invalid_argument(const char*__msg)
210{
211#ifndef _LIBCPP_NO_EXCEPTIONS
212 throw invalid_argument(__msg);
213#else
214_VSTD::abort();
215#endif
216}
217
218_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
219void __throw_length_error(const char*__msg)
220{
221#ifndef _LIBCPP_NO_EXCEPTIONS
222 throw length_error(__msg);
223#else
224_VSTD::abort();
225#endif
226}
227
228_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
229void __throw_out_of_range(const char*__msg)
230{
231#ifndef _LIBCPP_NO_EXCEPTIONS
232 throw out_of_range(__msg);
233#else
234_VSTD::abort();
235#endif
236}
237
238_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
239void __throw_range_error(const char*__msg)
240{
241#ifndef _LIBCPP_NO_EXCEPTIONS
242 throw range_error(__msg);
243#else
244_VSTD::abort();
245#endif
246}
247
248_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
249void __throw_overflow_error(const char*__msg)
250{
251#ifndef _LIBCPP_NO_EXCEPTIONS
252 throw overflow_error(__msg);
253#else
254_VSTD::abort();
255#endif
256}
257
258_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
259void __throw_underflow_error(const char*__msg)
260{
261#ifndef _LIBCPP_NO_EXCEPTIONS
262 throw underflow_error(__msg);
263#else
264_VSTD::abort();
265#endif
266}
267
268_LIBCPP_END_NAMESPACE_STD
269
Howard Hinnantbc8d3f92010-05-11 19:42:16270#endif // _LIBCPP_STDEXCEPT