xref: /aosp_15_r20/external/libcxx/include/stdexcept (revision 58b9f456b02922dfdb1fad8a988d5fd8765ecb80)
1*58b9f456SAndroid Build Coastguard Worker// -*- C++ -*-
2*58b9f456SAndroid Build Coastguard Worker//===--------------------------- stdexcept --------------------------------===//
3*58b9f456SAndroid Build Coastguard Worker//
4*58b9f456SAndroid Build Coastguard Worker//                     The LLVM Compiler Infrastructure
5*58b9f456SAndroid Build Coastguard Worker//
6*58b9f456SAndroid Build Coastguard Worker// This file is dual licensed under the MIT and the University of Illinois Open
7*58b9f456SAndroid Build Coastguard Worker// Source Licenses. See LICENSE.TXT for details.
8*58b9f456SAndroid Build Coastguard Worker//
9*58b9f456SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
10*58b9f456SAndroid Build Coastguard Worker
11*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_STDEXCEPT
12*58b9f456SAndroid Build Coastguard Worker#define _LIBCPP_STDEXCEPT
13*58b9f456SAndroid Build Coastguard Worker
14*58b9f456SAndroid Build Coastguard Worker/*
15*58b9f456SAndroid Build Coastguard Worker    stdexcept synopsis
16*58b9f456SAndroid Build Coastguard Worker
17*58b9f456SAndroid Build Coastguard Workernamespace std
18*58b9f456SAndroid Build Coastguard Worker{
19*58b9f456SAndroid Build Coastguard Worker
20*58b9f456SAndroid Build Coastguard Workerclass logic_error;
21*58b9f456SAndroid Build Coastguard Worker    class domain_error;
22*58b9f456SAndroid Build Coastguard Worker    class invalid_argument;
23*58b9f456SAndroid Build Coastguard Worker    class length_error;
24*58b9f456SAndroid Build Coastguard Worker    class out_of_range;
25*58b9f456SAndroid Build Coastguard Workerclass runtime_error;
26*58b9f456SAndroid Build Coastguard Worker    class range_error;
27*58b9f456SAndroid Build Coastguard Worker    class overflow_error;
28*58b9f456SAndroid Build Coastguard Worker    class underflow_error;
29*58b9f456SAndroid Build Coastguard Worker
30*58b9f456SAndroid Build Coastguard Workerfor each class xxx_error:
31*58b9f456SAndroid Build Coastguard Worker
32*58b9f456SAndroid Build Coastguard Workerclass xxx_error : public exception // at least indirectly
33*58b9f456SAndroid Build Coastguard Worker{
34*58b9f456SAndroid Build Coastguard Workerpublic:
35*58b9f456SAndroid Build Coastguard Worker    explicit xxx_error(const string& what_arg);
36*58b9f456SAndroid Build Coastguard Worker    explicit xxx_error(const char*   what_arg);
37*58b9f456SAndroid Build Coastguard Worker
38*58b9f456SAndroid Build Coastguard Worker    virtual const char* what() const noexcept // returns what_arg
39*58b9f456SAndroid Build Coastguard Worker};
40*58b9f456SAndroid Build Coastguard Worker
41*58b9f456SAndroid Build Coastguard Worker}  // std
42*58b9f456SAndroid Build Coastguard Worker
43*58b9f456SAndroid Build Coastguard Worker*/
44*58b9f456SAndroid Build Coastguard Worker
45*58b9f456SAndroid Build Coastguard Worker#include <__config>
46*58b9f456SAndroid Build Coastguard Worker#include <exception>
47*58b9f456SAndroid Build Coastguard Worker#include <iosfwd>  // for string forward decl
48*58b9f456SAndroid Build Coastguard Worker#ifdef _LIBCPP_NO_EXCEPTIONS
49*58b9f456SAndroid Build Coastguard Worker#include <cstdlib>
50*58b9f456SAndroid Build Coastguard Worker#endif
51*58b9f456SAndroid Build Coastguard Worker
52*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
53*58b9f456SAndroid Build Coastguard Worker#pragma GCC system_header
54*58b9f456SAndroid Build Coastguard Worker#endif
55*58b9f456SAndroid Build Coastguard Worker
56*58b9f456SAndroid Build Coastguard Worker_LIBCPP_BEGIN_NAMESPACE_STD
57*58b9f456SAndroid Build Coastguard Worker
58*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_HIDDEN __libcpp_refstring
59*58b9f456SAndroid Build Coastguard Worker{
60*58b9f456SAndroid Build Coastguard Worker    const char* __imp_;
61*58b9f456SAndroid Build Coastguard Worker
62*58b9f456SAndroid Build Coastguard Worker    bool __uses_refcount() const;
63*58b9f456SAndroid Build Coastguard Workerpublic:
64*58b9f456SAndroid Build Coastguard Worker    explicit __libcpp_refstring(const char* __msg);
65*58b9f456SAndroid Build Coastguard Worker    __libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT;
66*58b9f456SAndroid Build Coastguard Worker    __libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT;
67*58b9f456SAndroid Build Coastguard Worker    ~__libcpp_refstring();
68*58b9f456SAndroid Build Coastguard Worker
69*58b9f456SAndroid Build Coastguard Worker    const char* c_str() const _NOEXCEPT {return __imp_;}
70*58b9f456SAndroid Build Coastguard Worker};
71*58b9f456SAndroid Build Coastguard Worker
72*58b9f456SAndroid Build Coastguard Worker_LIBCPP_END_NAMESPACE_STD
73*58b9f456SAndroid Build Coastguard Worker
74*58b9f456SAndroid Build Coastguard Workernamespace std  // purposefully not using versioning namespace
75*58b9f456SAndroid Build Coastguard Worker{
76*58b9f456SAndroid Build Coastguard Worker
77*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_EXCEPTION_ABI logic_error
78*58b9f456SAndroid Build Coastguard Worker    : public exception
79*58b9f456SAndroid Build Coastguard Worker{
80*58b9f456SAndroid Build Coastguard Workerprivate:
81*58b9f456SAndroid Build Coastguard Worker    _VSTD::__libcpp_refstring __imp_;
82*58b9f456SAndroid Build Coastguard Workerpublic:
83*58b9f456SAndroid Build Coastguard Worker    explicit logic_error(const string&);
84*58b9f456SAndroid Build Coastguard Worker    explicit logic_error(const char*);
85*58b9f456SAndroid Build Coastguard Worker
86*58b9f456SAndroid Build Coastguard Worker    logic_error(const logic_error&) _NOEXCEPT;
87*58b9f456SAndroid Build Coastguard Worker    logic_error& operator=(const logic_error&) _NOEXCEPT;
88*58b9f456SAndroid Build Coastguard Worker
89*58b9f456SAndroid Build Coastguard Worker    virtual ~logic_error() _NOEXCEPT;
90*58b9f456SAndroid Build Coastguard Worker
91*58b9f456SAndroid Build Coastguard Worker    virtual const char* what() const _NOEXCEPT;
92*58b9f456SAndroid Build Coastguard Worker};
93*58b9f456SAndroid Build Coastguard Worker
94*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_EXCEPTION_ABI runtime_error
95*58b9f456SAndroid Build Coastguard Worker    : public exception
96*58b9f456SAndroid Build Coastguard Worker{
97*58b9f456SAndroid Build Coastguard Workerprivate:
98*58b9f456SAndroid Build Coastguard Worker    _VSTD::__libcpp_refstring __imp_;
99*58b9f456SAndroid Build Coastguard Workerpublic:
100*58b9f456SAndroid Build Coastguard Worker    explicit runtime_error(const string&);
101*58b9f456SAndroid Build Coastguard Worker    explicit runtime_error(const char*);
102*58b9f456SAndroid Build Coastguard Worker
103*58b9f456SAndroid Build Coastguard Worker    runtime_error(const runtime_error&) _NOEXCEPT;
104*58b9f456SAndroid Build Coastguard Worker    runtime_error& operator=(const runtime_error&) _NOEXCEPT;
105*58b9f456SAndroid Build Coastguard Worker
106*58b9f456SAndroid Build Coastguard Worker    virtual ~runtime_error() _NOEXCEPT;
107*58b9f456SAndroid Build Coastguard Worker
108*58b9f456SAndroid Build Coastguard Worker    virtual const char* what() const _NOEXCEPT;
109*58b9f456SAndroid Build Coastguard Worker};
110*58b9f456SAndroid Build Coastguard Worker
111*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_EXCEPTION_ABI domain_error
112*58b9f456SAndroid Build Coastguard Worker    : public logic_error
113*58b9f456SAndroid Build Coastguard Worker{
114*58b9f456SAndroid Build Coastguard Workerpublic:
115*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {}
116*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s)   : logic_error(__s) {}
117*58b9f456SAndroid Build Coastguard Worker
118*58b9f456SAndroid Build Coastguard Worker    virtual ~domain_error() _NOEXCEPT;
119*58b9f456SAndroid Build Coastguard Worker};
120*58b9f456SAndroid Build Coastguard Worker
121*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_EXCEPTION_ABI invalid_argument
122*58b9f456SAndroid Build Coastguard Worker    : public logic_error
123*58b9f456SAndroid Build Coastguard Worker{
124*58b9f456SAndroid Build Coastguard Workerpublic:
125*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {}
126*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s)   : logic_error(__s) {}
127*58b9f456SAndroid Build Coastguard Worker
128*58b9f456SAndroid Build Coastguard Worker    virtual ~invalid_argument() _NOEXCEPT;
129*58b9f456SAndroid Build Coastguard Worker};
130*58b9f456SAndroid Build Coastguard Worker
131*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_EXCEPTION_ABI length_error
132*58b9f456SAndroid Build Coastguard Worker    : public logic_error
133*58b9f456SAndroid Build Coastguard Worker{
134*58b9f456SAndroid Build Coastguard Workerpublic:
135*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {}
136*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s)   : logic_error(__s) {}
137*58b9f456SAndroid Build Coastguard Worker
138*58b9f456SAndroid Build Coastguard Worker    virtual ~length_error() _NOEXCEPT;
139*58b9f456SAndroid Build Coastguard Worker};
140*58b9f456SAndroid Build Coastguard Worker
141*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_EXCEPTION_ABI out_of_range
142*58b9f456SAndroid Build Coastguard Worker    : public logic_error
143*58b9f456SAndroid Build Coastguard Worker{
144*58b9f456SAndroid Build Coastguard Workerpublic:
145*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {}
146*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s)   : logic_error(__s) {}
147*58b9f456SAndroid Build Coastguard Worker
148*58b9f456SAndroid Build Coastguard Worker    virtual ~out_of_range() _NOEXCEPT;
149*58b9f456SAndroid Build Coastguard Worker};
150*58b9f456SAndroid Build Coastguard Worker
151*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_EXCEPTION_ABI range_error
152*58b9f456SAndroid Build Coastguard Worker    : public runtime_error
153*58b9f456SAndroid Build Coastguard Worker{
154*58b9f456SAndroid Build Coastguard Workerpublic:
155*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {}
156*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s)   : runtime_error(__s) {}
157*58b9f456SAndroid Build Coastguard Worker
158*58b9f456SAndroid Build Coastguard Worker    virtual ~range_error() _NOEXCEPT;
159*58b9f456SAndroid Build Coastguard Worker};
160*58b9f456SAndroid Build Coastguard Worker
161*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_EXCEPTION_ABI overflow_error
162*58b9f456SAndroid Build Coastguard Worker    : public runtime_error
163*58b9f456SAndroid Build Coastguard Worker{
164*58b9f456SAndroid Build Coastguard Workerpublic:
165*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {}
166*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s)   : runtime_error(__s) {}
167*58b9f456SAndroid Build Coastguard Worker
168*58b9f456SAndroid Build Coastguard Worker    virtual ~overflow_error() _NOEXCEPT;
169*58b9f456SAndroid Build Coastguard Worker};
170*58b9f456SAndroid Build Coastguard Worker
171*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_EXCEPTION_ABI underflow_error
172*58b9f456SAndroid Build Coastguard Worker    : public runtime_error
173*58b9f456SAndroid Build Coastguard Worker{
174*58b9f456SAndroid Build Coastguard Workerpublic:
175*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {}
176*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s)   : runtime_error(__s) {}
177*58b9f456SAndroid Build Coastguard Worker
178*58b9f456SAndroid Build Coastguard Worker    virtual ~underflow_error() _NOEXCEPT;
179*58b9f456SAndroid Build Coastguard Worker};
180*58b9f456SAndroid Build Coastguard Worker
181*58b9f456SAndroid Build Coastguard Worker}  // std
182*58b9f456SAndroid Build Coastguard Worker
183*58b9f456SAndroid Build Coastguard Worker_LIBCPP_BEGIN_NAMESPACE_STD
184*58b9f456SAndroid Build Coastguard Worker
185*58b9f456SAndroid Build Coastguard Worker// in the dylib
186*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
187*58b9f456SAndroid Build Coastguard Worker
188*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
189*58b9f456SAndroid Build Coastguard Workervoid __throw_logic_error(const char*__msg)
190*58b9f456SAndroid Build Coastguard Worker{
191*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
192*58b9f456SAndroid Build Coastguard Worker    throw logic_error(__msg);
193*58b9f456SAndroid Build Coastguard Worker#else
194*58b9f456SAndroid Build Coastguard Worker    ((void)__msg);
195*58b9f456SAndroid Build Coastguard Worker    _VSTD::abort();
196*58b9f456SAndroid Build Coastguard Worker#endif
197*58b9f456SAndroid Build Coastguard Worker}
198*58b9f456SAndroid Build Coastguard Worker
199*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
200*58b9f456SAndroid Build Coastguard Workervoid __throw_domain_error(const char*__msg)
201*58b9f456SAndroid Build Coastguard Worker{
202*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
203*58b9f456SAndroid Build Coastguard Worker    throw domain_error(__msg);
204*58b9f456SAndroid Build Coastguard Worker#else
205*58b9f456SAndroid Build Coastguard Worker    ((void)__msg);
206*58b9f456SAndroid Build Coastguard Worker    _VSTD::abort();
207*58b9f456SAndroid Build Coastguard Worker#endif
208*58b9f456SAndroid Build Coastguard Worker}
209*58b9f456SAndroid Build Coastguard Worker
210*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
211*58b9f456SAndroid Build Coastguard Workervoid __throw_invalid_argument(const char*__msg)
212*58b9f456SAndroid Build Coastguard Worker{
213*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
214*58b9f456SAndroid Build Coastguard Worker    throw invalid_argument(__msg);
215*58b9f456SAndroid Build Coastguard Worker#else
216*58b9f456SAndroid Build Coastguard Worker    ((void)__msg);
217*58b9f456SAndroid Build Coastguard Worker    _VSTD::abort();
218*58b9f456SAndroid Build Coastguard Worker#endif
219*58b9f456SAndroid Build Coastguard Worker}
220*58b9f456SAndroid Build Coastguard Worker
221*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
222*58b9f456SAndroid Build Coastguard Workervoid __throw_length_error(const char*__msg)
223*58b9f456SAndroid Build Coastguard Worker{
224*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
225*58b9f456SAndroid Build Coastguard Worker    throw length_error(__msg);
226*58b9f456SAndroid Build Coastguard Worker#else
227*58b9f456SAndroid Build Coastguard Worker    ((void)__msg);
228*58b9f456SAndroid Build Coastguard Worker    _VSTD::abort();
229*58b9f456SAndroid Build Coastguard Worker#endif
230*58b9f456SAndroid Build Coastguard Worker}
231*58b9f456SAndroid Build Coastguard Worker
232*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
233*58b9f456SAndroid Build Coastguard Workervoid __throw_out_of_range(const char*__msg)
234*58b9f456SAndroid Build Coastguard Worker{
235*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
236*58b9f456SAndroid Build Coastguard Worker    throw out_of_range(__msg);
237*58b9f456SAndroid Build Coastguard Worker#else
238*58b9f456SAndroid Build Coastguard Worker    ((void)__msg);
239*58b9f456SAndroid Build Coastguard Worker    _VSTD::abort();
240*58b9f456SAndroid Build Coastguard Worker#endif
241*58b9f456SAndroid Build Coastguard Worker}
242*58b9f456SAndroid Build Coastguard Worker
243*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
244*58b9f456SAndroid Build Coastguard Workervoid __throw_range_error(const char*__msg)
245*58b9f456SAndroid Build Coastguard Worker{
246*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
247*58b9f456SAndroid Build Coastguard Worker    throw range_error(__msg);
248*58b9f456SAndroid Build Coastguard Worker#else
249*58b9f456SAndroid Build Coastguard Worker    ((void)__msg);
250*58b9f456SAndroid Build Coastguard Worker    _VSTD::abort();
251*58b9f456SAndroid Build Coastguard Worker#endif
252*58b9f456SAndroid Build Coastguard Worker}
253*58b9f456SAndroid Build Coastguard Worker
254*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
255*58b9f456SAndroid Build Coastguard Workervoid __throw_overflow_error(const char*__msg)
256*58b9f456SAndroid Build Coastguard Worker{
257*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
258*58b9f456SAndroid Build Coastguard Worker    throw overflow_error(__msg);
259*58b9f456SAndroid Build Coastguard Worker#else
260*58b9f456SAndroid Build Coastguard Worker    ((void)__msg);
261*58b9f456SAndroid Build Coastguard Worker    _VSTD::abort();
262*58b9f456SAndroid Build Coastguard Worker#endif
263*58b9f456SAndroid Build Coastguard Worker}
264*58b9f456SAndroid Build Coastguard Worker
265*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
266*58b9f456SAndroid Build Coastguard Workervoid __throw_underflow_error(const char*__msg)
267*58b9f456SAndroid Build Coastguard Worker{
268*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
269*58b9f456SAndroid Build Coastguard Worker    throw underflow_error(__msg);
270*58b9f456SAndroid Build Coastguard Worker#else
271*58b9f456SAndroid Build Coastguard Worker    ((void)__msg);
272*58b9f456SAndroid Build Coastguard Worker    _VSTD::abort();
273*58b9f456SAndroid Build Coastguard Worker#endif
274*58b9f456SAndroid Build Coastguard Worker}
275*58b9f456SAndroid Build Coastguard Worker
276*58b9f456SAndroid Build Coastguard Worker_LIBCPP_END_NAMESPACE_STD
277*58b9f456SAndroid Build Coastguard Worker
278*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_STDEXCEPT
279