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
47*bfbd73f8SArthur O'Dwyer#include <cstdlib>
483e519524SHoward Hinnant
49073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
503e519524SHoward Hinnant#pragma GCC system_header
51073458b1SHoward Hinnant#endif
523e519524SHoward Hinnant
53a1fbf345SJoerg Sonnenberger_LIBCPP_BEGIN_NAMESPACE_STD
54a624409cSEric Fiselier
552710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
56a624409cSEric Fiselierclass _LIBCPP_HIDDEN __libcpp_refstring
57a624409cSEric Fiselier{
5889dd1dd2SEric Fiselier    const char* __imp_;
59a624409cSEric Fiselier
60a624409cSEric Fiselier    bool __uses_refcount() const;
61a624409cSEric Fiselierpublic:
629ffacf3dSEric Fiselier    explicit __libcpp_refstring(const char* __msg);
639ffacf3dSEric Fiselier    __libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT;
649ffacf3dSEric Fiselier    __libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT;
65a624409cSEric Fiselier    ~__libcpp_refstring();
66a624409cSEric Fiselier
67a624409cSEric Fiselier    const char* c_str() const _NOEXCEPT {return __imp_;}
68a1fbf345SJoerg Sonnenberger};
692710d8e1SEric Fiselier#endif // !_LIBCPP_ABI_VCRUNTIME
70a624409cSEric Fiselier
71a1fbf345SJoerg Sonnenberger_LIBCPP_END_NAMESPACE_STD
72a1fbf345SJoerg Sonnenberger
733e519524SHoward Hinnantnamespace std  // purposefully not using versioning namespace
743e519524SHoward Hinnant{
753e519524SHoward Hinnant
763e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI logic_error
773e519524SHoward Hinnant    : public exception
783e519524SHoward Hinnant{
792710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
803e519524SHoward Hinnantprivate:
81a1fbf345SJoerg Sonnenberger    _VSTD::__libcpp_refstring __imp_;
823e519524SHoward Hinnantpublic:
833e519524SHoward Hinnant    explicit logic_error(const string&);
843e519524SHoward Hinnant    explicit logic_error(const char*);
853e519524SHoward Hinnant
86a62f2899SHoward Hinnant    logic_error(const logic_error&) _NOEXCEPT;
87a62f2899SHoward Hinnant    logic_error& operator=(const logic_error&) _NOEXCEPT;
883e519524SHoward Hinnant
89a62f2899SHoward Hinnant    virtual ~logic_error() _NOEXCEPT;
903e519524SHoward Hinnant
91a62f2899SHoward Hinnant    virtual const char* what() const _NOEXCEPT;
922710d8e1SEric Fiselier#else
932710d8e1SEric Fiselierpublic:
942710d8e1SEric Fiselier    explicit logic_error(const _VSTD::string&); // Symbol uses versioned std::string
952710d8e1SEric Fiselier    _LIBCPP_INLINE_VISIBILITY explicit logic_error(const char* __s) : exception(__s) {}
962710d8e1SEric Fiselier#endif
973e519524SHoward Hinnant};
983e519524SHoward Hinnant
993e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI runtime_error
1003e519524SHoward Hinnant    : public exception
1013e519524SHoward Hinnant{
1022710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
1033e519524SHoward Hinnantprivate:
104a1fbf345SJoerg Sonnenberger    _VSTD::__libcpp_refstring __imp_;
1053e519524SHoward Hinnantpublic:
1063e519524SHoward Hinnant    explicit runtime_error(const string&);
1073e519524SHoward Hinnant    explicit runtime_error(const char*);
1083e519524SHoward Hinnant
109a62f2899SHoward Hinnant    runtime_error(const runtime_error&) _NOEXCEPT;
110a62f2899SHoward Hinnant    runtime_error& operator=(const runtime_error&) _NOEXCEPT;
1113e519524SHoward Hinnant
112a62f2899SHoward Hinnant    virtual ~runtime_error() _NOEXCEPT;
1133e519524SHoward Hinnant
114a62f2899SHoward Hinnant    virtual const char* what() const _NOEXCEPT;
1152710d8e1SEric Fiselier#else
1162710d8e1SEric Fiselierpublic:
1172710d8e1SEric Fiselier   explicit runtime_error(const _VSTD::string&); // Symbol uses versioned std::string
1182710d8e1SEric Fiselier   _LIBCPP_INLINE_VISIBILITY explicit runtime_error(const char* __s) : exception(__s) {}
1192710d8e1SEric Fiselier#endif // _LIBCPP_ABI_VCRUNTIME
1203e519524SHoward Hinnant};
1213e519524SHoward Hinnant
1223e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI domain_error
1233e519524SHoward Hinnant    : public logic_error
1243e519524SHoward Hinnant{
1253e519524SHoward Hinnantpublic:
1263e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {}
1273e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s)   : logic_error(__s) {}
1283e519524SHoward Hinnant
1292710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
130585a3cc3SDimitry Andric    domain_error(const domain_error&) _NOEXCEPT = default;
131a62f2899SHoward Hinnant    virtual ~domain_error() _NOEXCEPT;
1322710d8e1SEric Fiselier#endif
1333e519524SHoward Hinnant};
1343e519524SHoward Hinnant
1353e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI invalid_argument
1363e519524SHoward Hinnant    : public logic_error
1373e519524SHoward Hinnant{
1383e519524SHoward Hinnantpublic:
1393e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {}
1403e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s)   : logic_error(__s) {}
1413e519524SHoward Hinnant
1422710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
143585a3cc3SDimitry Andric    invalid_argument(const invalid_argument&) _NOEXCEPT = default;
144a62f2899SHoward Hinnant    virtual ~invalid_argument() _NOEXCEPT;
1452710d8e1SEric 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) {}
1542710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
155585a3cc3SDimitry Andric    length_error(const length_error&) _NOEXCEPT = default;
156a62f2899SHoward Hinnant    virtual ~length_error() _NOEXCEPT;
1572710d8e1SEric Fiselier#endif
1583e519524SHoward Hinnant};
1593e519524SHoward Hinnant
1603e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI out_of_range
1613e519524SHoward Hinnant    : public logic_error
1623e519524SHoward Hinnant{
1633e519524SHoward Hinnantpublic:
1643e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {}
1653e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s)   : logic_error(__s) {}
1663e519524SHoward Hinnant
1672710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
168585a3cc3SDimitry Andric    out_of_range(const out_of_range&) _NOEXCEPT = default;
169a62f2899SHoward Hinnant    virtual ~out_of_range() _NOEXCEPT;
1702710d8e1SEric Fiselier#endif
1713e519524SHoward Hinnant};
1723e519524SHoward Hinnant
1733e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI range_error
1743e519524SHoward Hinnant    : public runtime_error
1753e519524SHoward Hinnant{
1763e519524SHoward Hinnantpublic:
1773e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {}
1783e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s)   : runtime_error(__s) {}
1793e519524SHoward Hinnant
1802710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
181585a3cc3SDimitry Andric    range_error(const range_error&) _NOEXCEPT = default;
182a62f2899SHoward Hinnant    virtual ~range_error() _NOEXCEPT;
1832710d8e1SEric Fiselier#endif
1843e519524SHoward Hinnant};
1853e519524SHoward Hinnant
1863e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI overflow_error
1873e519524SHoward Hinnant    : public runtime_error
1883e519524SHoward Hinnant{
1893e519524SHoward Hinnantpublic:
1903e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {}
1913e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s)   : runtime_error(__s) {}
1923e519524SHoward Hinnant
1932710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
194585a3cc3SDimitry Andric    overflow_error(const overflow_error&) _NOEXCEPT = default;
195a62f2899SHoward Hinnant    virtual ~overflow_error() _NOEXCEPT;
1962710d8e1SEric Fiselier#endif
1973e519524SHoward Hinnant};
1983e519524SHoward Hinnant
1993e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI underflow_error
2003e519524SHoward Hinnant    : public runtime_error
2013e519524SHoward Hinnant{
2023e519524SHoward Hinnantpublic:
2033e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {}
2043e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s)   : runtime_error(__s) {}
2053e519524SHoward Hinnant
2062710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
207585a3cc3SDimitry Andric    underflow_error(const underflow_error&) _NOEXCEPT = default;
208a62f2899SHoward Hinnant    virtual ~underflow_error() _NOEXCEPT;
2092710d8e1SEric Fiselier#endif
2103e519524SHoward Hinnant};
2113e519524SHoward Hinnant
2123e519524SHoward Hinnant}  // std
2133e519524SHoward Hinnant
214d437fa5cSMarshall Clow_LIBCPP_BEGIN_NAMESPACE_STD
215d437fa5cSMarshall Clow
216d437fa5cSMarshall Clow// in the dylib
217d437fa5cSMarshall Clow_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
218d437fa5cSMarshall Clow
219dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
220d437fa5cSMarshall Clowvoid __throw_logic_error(const char*__msg)
221d437fa5cSMarshall Clow{
222d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
223d437fa5cSMarshall Clow    throw logic_error(__msg);
224d437fa5cSMarshall Clow#else
225fd838227SEric Fiselier    ((void)__msg);
226d437fa5cSMarshall Clow    _VSTD::abort();
227d437fa5cSMarshall Clow#endif
228d437fa5cSMarshall Clow}
229d437fa5cSMarshall Clow
230dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
231d437fa5cSMarshall Clowvoid __throw_domain_error(const char*__msg)
232d437fa5cSMarshall Clow{
233d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
234d437fa5cSMarshall Clow    throw domain_error(__msg);
235d437fa5cSMarshall Clow#else
236fd838227SEric Fiselier    ((void)__msg);
237d437fa5cSMarshall Clow    _VSTD::abort();
238d437fa5cSMarshall Clow#endif
239d437fa5cSMarshall Clow}
240d437fa5cSMarshall Clow
241dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
242d437fa5cSMarshall Clowvoid __throw_invalid_argument(const char*__msg)
243d437fa5cSMarshall Clow{
244d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
245d437fa5cSMarshall Clow    throw invalid_argument(__msg);
246d437fa5cSMarshall Clow#else
247fd838227SEric Fiselier    ((void)__msg);
248d437fa5cSMarshall Clow    _VSTD::abort();
249d437fa5cSMarshall Clow#endif
250d437fa5cSMarshall Clow}
251d437fa5cSMarshall Clow
252dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
253d437fa5cSMarshall Clowvoid __throw_length_error(const char*__msg)
254d437fa5cSMarshall Clow{
255d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
256d437fa5cSMarshall Clow    throw length_error(__msg);
257d437fa5cSMarshall Clow#else
258fd838227SEric Fiselier    ((void)__msg);
259d437fa5cSMarshall Clow    _VSTD::abort();
260d437fa5cSMarshall Clow#endif
261d437fa5cSMarshall Clow}
262d437fa5cSMarshall Clow
263dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
264d437fa5cSMarshall Clowvoid __throw_out_of_range(const char*__msg)
265d437fa5cSMarshall Clow{
266d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
267d437fa5cSMarshall Clow    throw out_of_range(__msg);
268d437fa5cSMarshall Clow#else
269fd838227SEric Fiselier    ((void)__msg);
270d437fa5cSMarshall Clow    _VSTD::abort();
271d437fa5cSMarshall Clow#endif
272d437fa5cSMarshall Clow}
273d437fa5cSMarshall Clow
274dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
275d437fa5cSMarshall Clowvoid __throw_range_error(const char*__msg)
276d437fa5cSMarshall Clow{
277d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
278d437fa5cSMarshall Clow    throw range_error(__msg);
279d437fa5cSMarshall Clow#else
280fd838227SEric Fiselier    ((void)__msg);
281d437fa5cSMarshall Clow    _VSTD::abort();
282d437fa5cSMarshall Clow#endif
283d437fa5cSMarshall Clow}
284d437fa5cSMarshall Clow
285dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
286d437fa5cSMarshall Clowvoid __throw_overflow_error(const char*__msg)
287d437fa5cSMarshall Clow{
288d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
289d437fa5cSMarshall Clow    throw overflow_error(__msg);
290d437fa5cSMarshall Clow#else
291fd838227SEric Fiselier    ((void)__msg);
292d437fa5cSMarshall Clow    _VSTD::abort();
293d437fa5cSMarshall Clow#endif
294d437fa5cSMarshall Clow}
295d437fa5cSMarshall Clow
296dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
297d437fa5cSMarshall Clowvoid __throw_underflow_error(const char*__msg)
298d437fa5cSMarshall Clow{
299d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
300d437fa5cSMarshall Clow    throw underflow_error(__msg);
301d437fa5cSMarshall Clow#else
302fd838227SEric Fiselier    ((void)__msg);
303d437fa5cSMarshall Clow    _VSTD::abort();
304d437fa5cSMarshall Clow#endif
305d437fa5cSMarshall Clow}
306d437fa5cSMarshall Clow
307d437fa5cSMarshall Clow_LIBCPP_END_NAMESPACE_STD
308d437fa5cSMarshall Clow
3093e519524SHoward Hinnant#endif // _LIBCPP_STDEXCEPT
310