13e519524SHoward Hinnant// -*- C++ -*-
2eb8650a7SLouis Dionne//===----------------------------------------------------------------------===//
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
44*385cc25aSLouis Dionne#include <__assert> // all public C++ headers provide the assertion handler
453e519524SHoward Hinnant#include <__config>
464d81a46fSArthur O'Dwyer#include <cstdlib>
473e519524SHoward Hinnant#include <exception>
483e519524SHoward Hinnant#include <iosfwd>  // for string forward decl
493e519524SHoward Hinnant
50073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
513e519524SHoward Hinnant#  pragma GCC system_header
52073458b1SHoward Hinnant#endif
533e519524SHoward Hinnant
54a1fbf345SJoerg Sonnenberger_LIBCPP_BEGIN_NAMESPACE_STD
55a624409cSEric Fiselier
562710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
57a624409cSEric Fiselierclass _LIBCPP_HIDDEN __libcpp_refstring
58a624409cSEric Fiselier{
5989dd1dd2SEric Fiselier    const char* __imp_;
60a624409cSEric Fiselier
61a624409cSEric Fiselier    bool __uses_refcount() const;
62a624409cSEric Fiselierpublic:
639ffacf3dSEric Fiselier    explicit __libcpp_refstring(const char* __msg);
649ffacf3dSEric Fiselier    __libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT;
659ffacf3dSEric Fiselier    __libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT;
66a624409cSEric Fiselier    ~__libcpp_refstring();
67a624409cSEric Fiselier
68a624409cSEric Fiselier    const char* c_str() const _NOEXCEPT {return __imp_;}
69a1fbf345SJoerg Sonnenberger};
702710d8e1SEric Fiselier#endif // !_LIBCPP_ABI_VCRUNTIME
71a624409cSEric Fiselier
72a1fbf345SJoerg Sonnenberger_LIBCPP_END_NAMESPACE_STD
73a1fbf345SJoerg Sonnenberger
743e519524SHoward Hinnantnamespace std  // purposefully not using versioning namespace
753e519524SHoward Hinnant{
763e519524SHoward Hinnant
773e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI logic_error
783e519524SHoward Hinnant    : public exception
793e519524SHoward Hinnant{
802710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
813e519524SHoward Hinnantprivate:
82a1fbf345SJoerg Sonnenberger    _VSTD::__libcpp_refstring __imp_;
833e519524SHoward Hinnantpublic:
843e519524SHoward Hinnant    explicit logic_error(const string&);
853e519524SHoward Hinnant    explicit logic_error(const char*);
863e519524SHoward Hinnant
87a62f2899SHoward Hinnant    logic_error(const logic_error&) _NOEXCEPT;
88a62f2899SHoward Hinnant    logic_error& operator=(const logic_error&) _NOEXCEPT;
893e519524SHoward Hinnant
90a62f2899SHoward Hinnant    virtual ~logic_error() _NOEXCEPT;
913e519524SHoward Hinnant
92a62f2899SHoward Hinnant    virtual const char* what() const _NOEXCEPT;
932710d8e1SEric Fiselier#else
942710d8e1SEric Fiselierpublic:
952710d8e1SEric Fiselier    explicit logic_error(const _VSTD::string&); // Symbol uses versioned std::string
962710d8e1SEric Fiselier    _LIBCPP_INLINE_VISIBILITY explicit logic_error(const char* __s) : exception(__s) {}
972710d8e1SEric Fiselier#endif
983e519524SHoward Hinnant};
993e519524SHoward Hinnant
1003e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI runtime_error
1013e519524SHoward Hinnant    : public exception
1023e519524SHoward Hinnant{
1032710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
1043e519524SHoward Hinnantprivate:
105a1fbf345SJoerg Sonnenberger    _VSTD::__libcpp_refstring __imp_;
1063e519524SHoward Hinnantpublic:
1073e519524SHoward Hinnant    explicit runtime_error(const string&);
1083e519524SHoward Hinnant    explicit runtime_error(const char*);
1093e519524SHoward Hinnant
110a62f2899SHoward Hinnant    runtime_error(const runtime_error&) _NOEXCEPT;
111a62f2899SHoward Hinnant    runtime_error& operator=(const runtime_error&) _NOEXCEPT;
1123e519524SHoward Hinnant
113a62f2899SHoward Hinnant    virtual ~runtime_error() _NOEXCEPT;
1143e519524SHoward Hinnant
115a62f2899SHoward Hinnant    virtual const char* what() const _NOEXCEPT;
1162710d8e1SEric Fiselier#else
1172710d8e1SEric Fiselierpublic:
1182710d8e1SEric Fiselier   explicit runtime_error(const _VSTD::string&); // Symbol uses versioned std::string
1192710d8e1SEric Fiselier   _LIBCPP_INLINE_VISIBILITY explicit runtime_error(const char* __s) : exception(__s) {}
1202710d8e1SEric Fiselier#endif // _LIBCPP_ABI_VCRUNTIME
1213e519524SHoward Hinnant};
1223e519524SHoward Hinnant
1233e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI domain_error
1243e519524SHoward Hinnant    : public logic_error
1253e519524SHoward Hinnant{
1263e519524SHoward Hinnantpublic:
1273e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {}
1283e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s)   : logic_error(__s) {}
1293e519524SHoward Hinnant
1302710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
131585a3cc3SDimitry Andric    domain_error(const domain_error&) _NOEXCEPT = default;
132a62f2899SHoward Hinnant    virtual ~domain_error() _NOEXCEPT;
1332710d8e1SEric 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
1432710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
144585a3cc3SDimitry Andric    invalid_argument(const invalid_argument&) _NOEXCEPT = default;
145a62f2899SHoward Hinnant    virtual ~invalid_argument() _NOEXCEPT;
1462710d8e1SEric Fiselier#endif
1473e519524SHoward Hinnant};
1483e519524SHoward Hinnant
1493e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI length_error
1503e519524SHoward Hinnant    : public logic_error
1513e519524SHoward Hinnant{
1523e519524SHoward Hinnantpublic:
1533e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {}
1543e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s)   : logic_error(__s) {}
1552710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
156585a3cc3SDimitry Andric    length_error(const length_error&) _NOEXCEPT = default;
157a62f2899SHoward Hinnant    virtual ~length_error() _NOEXCEPT;
1582710d8e1SEric Fiselier#endif
1593e519524SHoward Hinnant};
1603e519524SHoward Hinnant
1613e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI out_of_range
1623e519524SHoward Hinnant    : public logic_error
1633e519524SHoward Hinnant{
1643e519524SHoward Hinnantpublic:
1653e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {}
1663e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s)   : logic_error(__s) {}
1673e519524SHoward Hinnant
1682710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
169585a3cc3SDimitry Andric    out_of_range(const out_of_range&) _NOEXCEPT = default;
170a62f2899SHoward Hinnant    virtual ~out_of_range() _NOEXCEPT;
1712710d8e1SEric Fiselier#endif
1723e519524SHoward Hinnant};
1733e519524SHoward Hinnant
1743e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI range_error
1753e519524SHoward Hinnant    : public runtime_error
1763e519524SHoward Hinnant{
1773e519524SHoward Hinnantpublic:
1783e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {}
1793e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s)   : runtime_error(__s) {}
1803e519524SHoward Hinnant
1812710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
182585a3cc3SDimitry Andric    range_error(const range_error&) _NOEXCEPT = default;
183a62f2899SHoward Hinnant    virtual ~range_error() _NOEXCEPT;
1842710d8e1SEric Fiselier#endif
1853e519524SHoward Hinnant};
1863e519524SHoward Hinnant
1873e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI overflow_error
1883e519524SHoward Hinnant    : public runtime_error
1893e519524SHoward Hinnant{
1903e519524SHoward Hinnantpublic:
1913e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {}
1923e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s)   : runtime_error(__s) {}
1933e519524SHoward Hinnant
1942710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
195585a3cc3SDimitry Andric    overflow_error(const overflow_error&) _NOEXCEPT = default;
196a62f2899SHoward Hinnant    virtual ~overflow_error() _NOEXCEPT;
1972710d8e1SEric Fiselier#endif
1983e519524SHoward Hinnant};
1993e519524SHoward Hinnant
2003e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI underflow_error
2013e519524SHoward Hinnant    : public runtime_error
2023e519524SHoward Hinnant{
2033e519524SHoward Hinnantpublic:
2043e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {}
2053e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s)   : runtime_error(__s) {}
2063e519524SHoward Hinnant
2072710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME
208585a3cc3SDimitry Andric    underflow_error(const underflow_error&) _NOEXCEPT = default;
209a62f2899SHoward Hinnant    virtual ~underflow_error() _NOEXCEPT;
2102710d8e1SEric Fiselier#endif
2113e519524SHoward Hinnant};
2123e519524SHoward Hinnant
213d2b0df35SNikolas Klauser} // namespace std
2143e519524SHoward Hinnant
215d437fa5cSMarshall Clow_LIBCPP_BEGIN_NAMESPACE_STD
216d437fa5cSMarshall Clow
217d437fa5cSMarshall Clow// in the dylib
218d437fa5cSMarshall Clow_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
219d437fa5cSMarshall Clow
220dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
221d437fa5cSMarshall Clowvoid __throw_logic_error(const char*__msg)
222d437fa5cSMarshall Clow{
223d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
224d437fa5cSMarshall Clow    throw logic_error(__msg);
225d437fa5cSMarshall Clow#else
226fd838227SEric Fiselier    ((void)__msg);
227d437fa5cSMarshall Clow    _VSTD::abort();
228d437fa5cSMarshall Clow#endif
229d437fa5cSMarshall Clow}
230d437fa5cSMarshall Clow
231dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
232d437fa5cSMarshall Clowvoid __throw_domain_error(const char*__msg)
233d437fa5cSMarshall Clow{
234d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
235d437fa5cSMarshall Clow    throw domain_error(__msg);
236d437fa5cSMarshall Clow#else
237fd838227SEric Fiselier    ((void)__msg);
238d437fa5cSMarshall Clow    _VSTD::abort();
239d437fa5cSMarshall Clow#endif
240d437fa5cSMarshall Clow}
241d437fa5cSMarshall Clow
242dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
243d437fa5cSMarshall Clowvoid __throw_invalid_argument(const char*__msg)
244d437fa5cSMarshall Clow{
245d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
246d437fa5cSMarshall Clow    throw invalid_argument(__msg);
247d437fa5cSMarshall Clow#else
248fd838227SEric Fiselier    ((void)__msg);
249d437fa5cSMarshall Clow    _VSTD::abort();
250d437fa5cSMarshall Clow#endif
251d437fa5cSMarshall Clow}
252d437fa5cSMarshall Clow
253dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
254d437fa5cSMarshall Clowvoid __throw_length_error(const char*__msg)
255d437fa5cSMarshall Clow{
256d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
257d437fa5cSMarshall Clow    throw length_error(__msg);
258d437fa5cSMarshall Clow#else
259fd838227SEric Fiselier    ((void)__msg);
260d437fa5cSMarshall Clow    _VSTD::abort();
261d437fa5cSMarshall Clow#endif
262d437fa5cSMarshall Clow}
263d437fa5cSMarshall Clow
264dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
265d437fa5cSMarshall Clowvoid __throw_out_of_range(const char*__msg)
266d437fa5cSMarshall Clow{
267d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
268d437fa5cSMarshall Clow    throw out_of_range(__msg);
269d437fa5cSMarshall Clow#else
270fd838227SEric Fiselier    ((void)__msg);
271d437fa5cSMarshall Clow    _VSTD::abort();
272d437fa5cSMarshall Clow#endif
273d437fa5cSMarshall Clow}
274d437fa5cSMarshall Clow
275dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
276d437fa5cSMarshall Clowvoid __throw_range_error(const char*__msg)
277d437fa5cSMarshall Clow{
278d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
279d437fa5cSMarshall Clow    throw range_error(__msg);
280d437fa5cSMarshall Clow#else
281fd838227SEric Fiselier    ((void)__msg);
282d437fa5cSMarshall Clow    _VSTD::abort();
283d437fa5cSMarshall Clow#endif
284d437fa5cSMarshall Clow}
285d437fa5cSMarshall Clow
286dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
287d437fa5cSMarshall Clowvoid __throw_overflow_error(const char*__msg)
288d437fa5cSMarshall Clow{
289d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
290d437fa5cSMarshall Clow    throw overflow_error(__msg);
291d437fa5cSMarshall Clow#else
292fd838227SEric Fiselier    ((void)__msg);
293d437fa5cSMarshall Clow    _VSTD::abort();
294d437fa5cSMarshall Clow#endif
295d437fa5cSMarshall Clow}
296d437fa5cSMarshall Clow
297dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
298d437fa5cSMarshall Clowvoid __throw_underflow_error(const char*__msg)
299d437fa5cSMarshall Clow{
300d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS
301d437fa5cSMarshall Clow    throw underflow_error(__msg);
302d437fa5cSMarshall Clow#else
303fd838227SEric Fiselier    ((void)__msg);
304d437fa5cSMarshall Clow    _VSTD::abort();
305d437fa5cSMarshall Clow#endif
306d437fa5cSMarshall Clow}
307d437fa5cSMarshall Clow
308d437fa5cSMarshall Clow_LIBCPP_END_NAMESPACE_STD
309d437fa5cSMarshall Clow
3103e519524SHoward Hinnant#endif // _LIBCPP_STDEXCEPT
311