13e519524SHoward Hinnant// -*- C++ -*-
23e519524SHoward Hinnant//===--------------------------- stdexcept --------------------------------===//
33e519524SHoward Hinnant//
457b08b09SChandler Carruth// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
557b08b09SChandler Carruth// See https://llvm.org/LICENSE.txt for license information.
657b08b09SChandler Carruth// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
73e519524SHoward Hinnant//
83e519524SHoward Hinnant//===----------------------------------------------------------------------===//
93e519524SHoward Hinnant
103e519524SHoward Hinnant#ifndef _LIBCPP_STDEXCEPT
113e519524SHoward Hinnant#define _LIBCPP_STDEXCEPT
123e519524SHoward Hinnant
133e519524SHoward Hinnant/*
143e519524SHoward Hinnant    stdexcept synopsis
153e519524SHoward Hinnant
163e519524SHoward Hinnantnamespace std
173e519524SHoward Hinnant{
183e519524SHoward Hinnant
193e519524SHoward Hinnantclass logic_error;
203e519524SHoward Hinnant    class domain_error;
213e519524SHoward Hinnant    class invalid_argument;
223e519524SHoward Hinnant    class length_error;
233e519524SHoward Hinnant    class out_of_range;
243e519524SHoward Hinnantclass runtime_error;
253e519524SHoward Hinnant    class range_error;
263e519524SHoward Hinnant    class overflow_error;
273e519524SHoward Hinnant    class underflow_error;
283e519524SHoward Hinnant
293e519524SHoward Hinnantfor each class xxx_error:
303e519524SHoward Hinnant
313e519524SHoward Hinnantclass xxx_error : public exception // at least indirectly
323e519524SHoward Hinnant{
333e519524SHoward Hinnantpublic:
343e519524SHoward Hinnant    explicit xxx_error(const string& what_arg);
35a62f2899SHoward Hinnant    explicit xxx_error(const char*   what_arg);
363e519524SHoward Hinnant
37a62f2899SHoward Hinnant    virtual const char* what() const noexcept // returns what_arg
383e519524SHoward Hinnant};
393e519524SHoward Hinnant
403e519524SHoward Hinnant}  // std
413e519524SHoward Hinnant
423e519524SHoward Hinnant*/
433e519524SHoward Hinnant
443e519524SHoward Hinnant#include <__config>
453e519524SHoward Hinnant#include <exception>
463e519524SHoward Hinnant#include <iosfwd>  // for string forward decl
47b683ec20SEric Fiselier#ifdef _LIBCPP_NO_EXCEPTIONS
48b683ec20SEric Fiselier#include <cstdlib>
49b683ec20SEric Fiselier#endif
503e519524SHoward Hinnant
51073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
523e519524SHoward Hinnant#pragma GCC system_header
53073458b1SHoward Hinnant#endif
543e519524SHoward Hinnant
55a1fbf345SJoerg Sonnenberger_LIBCPP_BEGIN_NAMESPACE_STD
56a624409cSEric Fiselier
57*2710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
58a624409cSEric Fiselierclass _LIBCPP_HIDDEN __libcpp_refstring
59a624409cSEric Fiselier{
6089dd1dd2SEric Fiselier    const char* __imp_;
61a624409cSEric Fiselier
62a624409cSEric Fiselier    bool __uses_refcount() const;
63a624409cSEric Fiselierpublic:
649ffacf3dSEric Fiselier    explicit __libcpp_refstring(const char* __msg);
659ffacf3dSEric Fiselier    __libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT;
669ffacf3dSEric Fiselier    __libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT;
67a624409cSEric Fiselier    ~__libcpp_refstring();
68a624409cSEric Fiselier
69a624409cSEric Fiselier    const char* c_str() const _NOEXCEPT {return __imp_;}
70a1fbf345SJoerg Sonnenberger};
71*2710d8e1SEric Fiselier#endif // !_LIBCPP_ABI_VCRUNTIME
72a624409cSEric Fiselier
73a1fbf345SJoerg Sonnenberger_LIBCPP_END_NAMESPACE_STD
74a1fbf345SJoerg Sonnenberger
753e519524SHoward Hinnantnamespace std  // purposefully not using versioning namespace
763e519524SHoward Hinnant{
773e519524SHoward Hinnant
783e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI logic_error
793e519524SHoward Hinnant    : public exception
803e519524SHoward Hinnant{
81*2710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
823e519524SHoward Hinnantprivate:
83a1fbf345SJoerg Sonnenberger    _VSTD::__libcpp_refstring __imp_;
843e519524SHoward Hinnantpublic:
853e519524SHoward Hinnant    explicit logic_error(const string&);
863e519524SHoward Hinnant    explicit logic_error(const char*);
873e519524SHoward Hinnant
88a62f2899SHoward Hinnant    logic_error(const logic_error&) _NOEXCEPT;
89a62f2899SHoward Hinnant    logic_error& operator=(const logic_error&) _NOEXCEPT;
903e519524SHoward Hinnant
91a62f2899SHoward Hinnant    virtual ~logic_error() _NOEXCEPT;
923e519524SHoward Hinnant
93a62f2899SHoward Hinnant    virtual const char* what() const _NOEXCEPT;
94*2710d8e1SEric Fiselier#else
95*2710d8e1SEric Fiselierpublic:
96*2710d8e1SEric Fiselier    explicit logic_error(const _VSTD::string&); // Symbol uses versioned std::string
97*2710d8e1SEric Fiselier    _LIBCPP_INLINE_VISIBILITY explicit logic_error(const char* __s) : exception(__s) {}
98*2710d8e1SEric Fiselier#endif
993e519524SHoward Hinnant};
1003e519524SHoward Hinnant
1013e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI runtime_error
1023e519524SHoward Hinnant    : public exception
1033e519524SHoward Hinnant{
104*2710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
1053e519524SHoward Hinnantprivate:
106a1fbf345SJoerg Sonnenberger    _VSTD::__libcpp_refstring __imp_;
1073e519524SHoward Hinnantpublic:
1083e519524SHoward Hinnant    explicit runtime_error(const string&);
1093e519524SHoward Hinnant    explicit runtime_error(const char*);
1103e519524SHoward Hinnant
111a62f2899SHoward Hinnant    runtime_error(const runtime_error&) _NOEXCEPT;
112a62f2899SHoward Hinnant    runtime_error& operator=(const runtime_error&) _NOEXCEPT;
1133e519524SHoward Hinnant
114a62f2899SHoward Hinnant    virtual ~runtime_error() _NOEXCEPT;
1153e519524SHoward Hinnant
116a62f2899SHoward Hinnant    virtual const char* what() const _NOEXCEPT;
117*2710d8e1SEric Fiselier#else
118*2710d8e1SEric Fiselierpublic:
119*2710d8e1SEric Fiselier   explicit runtime_error(const _VSTD::string&); // Symbol uses versioned std::string
120*2710d8e1SEric Fiselier   _LIBCPP_INLINE_VISIBILITY explicit runtime_error(const char* __s) : exception(__s) {}
121*2710d8e1SEric Fiselier#endif // _LIBCPP_ABI_VCRUNTIME
1223e519524SHoward Hinnant};
1233e519524SHoward Hinnant
1243e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI domain_error
1253e519524SHoward Hinnant    : public logic_error
1263e519524SHoward Hinnant{
1273e519524SHoward Hinnantpublic:
1283e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {}
1293e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s)   : logic_error(__s) {}
1303e519524SHoward Hinnant
131*2710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
132a62f2899SHoward Hinnant    virtual ~domain_error() _NOEXCEPT;
133*2710d8e1SEric Fiselier#endif
1343e519524SHoward Hinnant};
1353e519524SHoward Hinnant
1363e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI invalid_argument
1373e519524SHoward Hinnant    : public logic_error
1383e519524SHoward Hinnant{
1393e519524SHoward Hinnantpublic:
1403e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {}
1413e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s)   : logic_error(__s) {}
1423e519524SHoward Hinnant
143*2710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
144a62f2899SHoward Hinnant    virtual ~invalid_argument() _NOEXCEPT;
145*2710d8e1SEric Fiselier#endif
1463e519524SHoward Hinnant};
1473e519524SHoward Hinnant
1483e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI length_error
1493e519524SHoward Hinnant    : public logic_error
1503e519524SHoward Hinnant{
1513e519524SHoward Hinnantpublic:
1523e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {}
1533e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s)   : logic_error(__s) {}
154*2710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
155a62f2899SHoward Hinnant    virtual ~length_error() _NOEXCEPT;
156*2710d8e1SEric Fiselier#endif
1573e519524SHoward Hinnant};
1583e519524SHoward Hinnant
1593e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI out_of_range
1603e519524SHoward Hinnant    : public logic_error
1613e519524SHoward Hinnant{
1623e519524SHoward Hinnantpublic:
1633e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {}
1643e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s)   : logic_error(__s) {}
1653e519524SHoward Hinnant
166*2710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
167a62f2899SHoward Hinnant    virtual ~out_of_range() _NOEXCEPT;
168*2710d8e1SEric Fiselier#endif
1693e519524SHoward Hinnant};
1703e519524SHoward Hinnant
1713e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI range_error
1723e519524SHoward Hinnant    : public runtime_error
1733e519524SHoward Hinnant{
1743e519524SHoward Hinnantpublic:
1753e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {}
1763e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s)   : runtime_error(__s) {}
1773e519524SHoward Hinnant
178*2710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
179a62f2899SHoward Hinnant    virtual ~range_error() _NOEXCEPT;
180*2710d8e1SEric Fiselier#endif
1813e519524SHoward Hinnant};
1823e519524SHoward Hinnant
1833e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI overflow_error
1843e519524SHoward Hinnant    : public runtime_error
1853e519524SHoward Hinnant{
1863e519524SHoward Hinnantpublic:
1873e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {}
1883e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s)   : runtime_error(__s) {}
1893e519524SHoward Hinnant
190*2710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
191a62f2899SHoward Hinnant    virtual ~overflow_error() _NOEXCEPT;
192*2710d8e1SEric Fiselier#endif
1933e519524SHoward Hinnant};
1943e519524SHoward Hinnant
1953e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI underflow_error
1963e519524SHoward Hinnant    : public runtime_error
1973e519524SHoward Hinnant{
1983e519524SHoward Hinnantpublic:
1993e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {}
2003e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s)   : runtime_error(__s) {}
2013e519524SHoward Hinnant
202*2710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
203a62f2899SHoward Hinnant    virtual ~underflow_error() _NOEXCEPT;
204*2710d8e1SEric Fiselier#endif
2053e519524SHoward Hinnant};
2063e519524SHoward Hinnant
2073e519524SHoward Hinnant}  // std
2083e519524SHoward Hinnant
209d437fa5cSMarshall Clow_LIBCPP_BEGIN_NAMESPACE_STD
210d437fa5cSMarshall Clow
211d437fa5cSMarshall Clow// in the dylib
212d437fa5cSMarshall Clow_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
213d437fa5cSMarshall Clow
214dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
215d437fa5cSMarshall Clowvoid __throw_logic_error(const char*__msg)
216d437fa5cSMarshall Clow{
217d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
218d437fa5cSMarshall Clow    throw logic_error(__msg);
219d437fa5cSMarshall Clow#else
220fd838227SEric Fiselier    ((void)__msg);
221d437fa5cSMarshall Clow    _VSTD::abort();
222d437fa5cSMarshall Clow#endif
223d437fa5cSMarshall Clow}
224d437fa5cSMarshall Clow
225dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
226d437fa5cSMarshall Clowvoid __throw_domain_error(const char*__msg)
227d437fa5cSMarshall Clow{
228d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
229d437fa5cSMarshall Clow    throw domain_error(__msg);
230d437fa5cSMarshall Clow#else
231fd838227SEric Fiselier    ((void)__msg);
232d437fa5cSMarshall Clow    _VSTD::abort();
233d437fa5cSMarshall Clow#endif
234d437fa5cSMarshall Clow}
235d437fa5cSMarshall Clow
236dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
237d437fa5cSMarshall Clowvoid __throw_invalid_argument(const char*__msg)
238d437fa5cSMarshall Clow{
239d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
240d437fa5cSMarshall Clow    throw invalid_argument(__msg);
241d437fa5cSMarshall Clow#else
242fd838227SEric Fiselier    ((void)__msg);
243d437fa5cSMarshall Clow    _VSTD::abort();
244d437fa5cSMarshall Clow#endif
245d437fa5cSMarshall Clow}
246d437fa5cSMarshall Clow
247dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
248d437fa5cSMarshall Clowvoid __throw_length_error(const char*__msg)
249d437fa5cSMarshall Clow{
250d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
251d437fa5cSMarshall Clow    throw length_error(__msg);
252d437fa5cSMarshall Clow#else
253fd838227SEric Fiselier    ((void)__msg);
254d437fa5cSMarshall Clow    _VSTD::abort();
255d437fa5cSMarshall Clow#endif
256d437fa5cSMarshall Clow}
257d437fa5cSMarshall Clow
258dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
259d437fa5cSMarshall Clowvoid __throw_out_of_range(const char*__msg)
260d437fa5cSMarshall Clow{
261d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
262d437fa5cSMarshall Clow    throw out_of_range(__msg);
263d437fa5cSMarshall Clow#else
264fd838227SEric Fiselier    ((void)__msg);
265d437fa5cSMarshall Clow    _VSTD::abort();
266d437fa5cSMarshall Clow#endif
267d437fa5cSMarshall Clow}
268d437fa5cSMarshall Clow
269dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
270d437fa5cSMarshall Clowvoid __throw_range_error(const char*__msg)
271d437fa5cSMarshall Clow{
272d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
273d437fa5cSMarshall Clow    throw range_error(__msg);
274d437fa5cSMarshall Clow#else
275fd838227SEric Fiselier    ((void)__msg);
276d437fa5cSMarshall Clow    _VSTD::abort();
277d437fa5cSMarshall Clow#endif
278d437fa5cSMarshall Clow}
279d437fa5cSMarshall Clow
280dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
281d437fa5cSMarshall Clowvoid __throw_overflow_error(const char*__msg)
282d437fa5cSMarshall Clow{
283d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
284d437fa5cSMarshall Clow    throw overflow_error(__msg);
285d437fa5cSMarshall Clow#else
286fd838227SEric Fiselier    ((void)__msg);
287d437fa5cSMarshall Clow    _VSTD::abort();
288d437fa5cSMarshall Clow#endif
289d437fa5cSMarshall Clow}
290d437fa5cSMarshall Clow
291dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
292d437fa5cSMarshall Clowvoid __throw_underflow_error(const char*__msg)
293d437fa5cSMarshall Clow{
294d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
295d437fa5cSMarshall Clow    throw underflow_error(__msg);
296d437fa5cSMarshall Clow#else
297fd838227SEric Fiselier    ((void)__msg);
298d437fa5cSMarshall Clow    _VSTD::abort();
299d437fa5cSMarshall Clow#endif
300d437fa5cSMarshall Clow}
301d437fa5cSMarshall Clow
302d437fa5cSMarshall Clow_LIBCPP_END_NAMESPACE_STD
303d437fa5cSMarshall Clow
3043e519524SHoward Hinnant#endif  // _LIBCPP_STDEXCEPT
305