blob: b78d5d60273bde207d2ac492ecf1f3ba947c5497 [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#ifndef _LIBCPP___REFSTRING
57_LIBCPP_BEGIN_NAMESPACE_STD
58class _LIBCPP_HIDDEN __libcpp_refstring {
Eric Fiselier566bcb42016-04-21 22:54:2159#ifdef __clang__
60 const char *__imp_ __attribute__((__unused__)); // only clang emits a warning
61#else
62 const char *__imp_;
63#endif
Joerg Sonnenberger55622072014-04-30 19:54:1164};
65_LIBCPP_END_NAMESPACE_STD
66#endif
67
Howard Hinnantbc8d3f92010-05-11 19:42:1668namespace std // purposefully not using versioning namespace
69{
70
71class _LIBCPP_EXCEPTION_ABI logic_error
72 : public exception
73{
74private:
Joerg Sonnenberger55622072014-04-30 19:54:1175 _VSTD::__libcpp_refstring __imp_;
Howard Hinnantbc8d3f92010-05-11 19:42:1676public:
77 explicit logic_error(const string&);
78 explicit logic_error(const char*);
79
Howard Hinnant1e15fd12011-05-26 19:48:0180 logic_error(const logic_error&) _NOEXCEPT;
81 logic_error& operator=(const logic_error&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:1682
Howard Hinnant1e15fd12011-05-26 19:48:0183 virtual ~logic_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:1684
Howard Hinnant1e15fd12011-05-26 19:48:0185 virtual const char* what() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:1686};
87
88class _LIBCPP_EXCEPTION_ABI runtime_error
89 : public exception
90{
91private:
Joerg Sonnenberger55622072014-04-30 19:54:1192 _VSTD::__libcpp_refstring __imp_;
Howard Hinnantbc8d3f92010-05-11 19:42:1693public:
94 explicit runtime_error(const string&);
95 explicit runtime_error(const char*);
96
Howard Hinnant1e15fd12011-05-26 19:48:0197 runtime_error(const runtime_error&) _NOEXCEPT;
98 runtime_error& operator=(const runtime_error&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:1699
Howard Hinnant1e15fd12011-05-26 19:48:01100 virtual ~runtime_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16101
Howard Hinnant1e15fd12011-05-26 19:48:01102 virtual const char* what() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16103};
104
105class _LIBCPP_EXCEPTION_ABI domain_error
106 : public logic_error
107{
108public:
109 _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {}
110 _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {}
111
Howard Hinnant1e15fd12011-05-26 19:48:01112 virtual ~domain_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16113};
114
115class _LIBCPP_EXCEPTION_ABI invalid_argument
116 : public logic_error
117{
118public:
119 _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {}
120 _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {}
121
Howard Hinnant1e15fd12011-05-26 19:48:01122 virtual ~invalid_argument() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16123};
124
125class _LIBCPP_EXCEPTION_ABI length_error
126 : public logic_error
127{
128public:
129 _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {}
130 _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {}
131
Howard Hinnant1e15fd12011-05-26 19:48:01132 virtual ~length_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16133};
134
135class _LIBCPP_EXCEPTION_ABI out_of_range
136 : public logic_error
137{
138public:
139 _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {}
140 _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {}
141
Howard Hinnant1e15fd12011-05-26 19:48:01142 virtual ~out_of_range() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16143};
144
145class _LIBCPP_EXCEPTION_ABI range_error
146 : public runtime_error
147{
148public:
149 _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {}
150 _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {}
151
Howard Hinnant1e15fd12011-05-26 19:48:01152 virtual ~range_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16153};
154
155class _LIBCPP_EXCEPTION_ABI overflow_error
156 : public runtime_error
157{
158public:
159 _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {}
160 _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {}
161
Howard Hinnant1e15fd12011-05-26 19:48:01162 virtual ~overflow_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16163};
164
165class _LIBCPP_EXCEPTION_ABI underflow_error
166 : public runtime_error
167{
168public:
169 _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {}
170 _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {}
171
Howard Hinnant1e15fd12011-05-26 19:48:01172 virtual ~underflow_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16173};
174
Howard Hinnantbc8d3f92010-05-11 19:42:16175} // std
176
Marshall Clow14c09a22016-08-25 15:09:01177_LIBCPP_BEGIN_NAMESPACE_STD
178
179// in the dylib
180_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
181
182_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
183void __throw_logic_error(const char*__msg)
184{
185#ifndef _LIBCPP_NO_EXCEPTIONS
186 throw logic_error(__msg);
187#else
188_VSTD::abort();
189#endif
190}
191
192_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
193void __throw_domain_error(const char*__msg)
194{
195#ifndef _LIBCPP_NO_EXCEPTIONS
196 throw domain_error(__msg);
197#else
198_VSTD::abort();
199#endif
200}
201
202_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
203void __throw_invalid_argument(const char*__msg)
204{
205#ifndef _LIBCPP_NO_EXCEPTIONS
206 throw invalid_argument(__msg);
207#else
208_VSTD::abort();
209#endif
210}
211
212_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
213void __throw_length_error(const char*__msg)
214{
215#ifndef _LIBCPP_NO_EXCEPTIONS
216 throw length_error(__msg);
217#else
218_VSTD::abort();
219#endif
220}
221
222_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
223void __throw_out_of_range(const char*__msg)
224{
225#ifndef _LIBCPP_NO_EXCEPTIONS
226 throw out_of_range(__msg);
227#else
228_VSTD::abort();
229#endif
230}
231
232_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
233void __throw_range_error(const char*__msg)
234{
235#ifndef _LIBCPP_NO_EXCEPTIONS
236 throw range_error(__msg);
237#else
238_VSTD::abort();
239#endif
240}
241
242_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
243void __throw_overflow_error(const char*__msg)
244{
245#ifndef _LIBCPP_NO_EXCEPTIONS
246 throw overflow_error(__msg);
247#else
248_VSTD::abort();
249#endif
250}
251
252_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
253void __throw_underflow_error(const char*__msg)
254{
255#ifndef _LIBCPP_NO_EXCEPTIONS
256 throw underflow_error(__msg);
257#else
258_VSTD::abort();
259#endif
260}
261
262_LIBCPP_END_NAMESPACE_STD
263
Howard Hinnantbc8d3f92010-05-11 19:42:16264#endif // _LIBCPP_STDEXCEPT