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 572710d8e1SEric 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}; 712710d8e1SEric 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{ 812710d8e1SEric 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; 942710d8e1SEric Fiselier#else 952710d8e1SEric Fiselierpublic: 962710d8e1SEric Fiselier explicit logic_error(const _VSTD::string&); // Symbol uses versioned std::string 972710d8e1SEric Fiselier _LIBCPP_INLINE_VISIBILITY explicit logic_error(const char* __s) : exception(__s) {} 982710d8e1SEric Fiselier#endif 993e519524SHoward Hinnant}; 1003e519524SHoward Hinnant 1013e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI runtime_error 1023e519524SHoward Hinnant : public exception 1033e519524SHoward Hinnant{ 1042710d8e1SEric 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; 1172710d8e1SEric Fiselier#else 1182710d8e1SEric Fiselierpublic: 1192710d8e1SEric Fiselier explicit runtime_error(const _VSTD::string&); // Symbol uses versioned std::string 1202710d8e1SEric Fiselier _LIBCPP_INLINE_VISIBILITY explicit runtime_error(const char* __s) : exception(__s) {} 1212710d8e1SEric 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 1312710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME 132*585a3cc3SDimitry Andric domain_error(const domain_error&) _NOEXCEPT = default; 133a62f2899SHoward Hinnant virtual ~domain_error() _NOEXCEPT; 1342710d8e1SEric Fiselier#endif 1353e519524SHoward Hinnant}; 1363e519524SHoward Hinnant 1373e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI invalid_argument 1383e519524SHoward Hinnant : public logic_error 1393e519524SHoward Hinnant{ 1403e519524SHoward Hinnantpublic: 1413e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {} 1423e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {} 1433e519524SHoward Hinnant 1442710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME 145*585a3cc3SDimitry Andric invalid_argument(const invalid_argument&) _NOEXCEPT = default; 146a62f2899SHoward Hinnant virtual ~invalid_argument() _NOEXCEPT; 1472710d8e1SEric Fiselier#endif 1483e519524SHoward Hinnant}; 1493e519524SHoward Hinnant 1503e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI length_error 1513e519524SHoward Hinnant : public logic_error 1523e519524SHoward Hinnant{ 1533e519524SHoward Hinnantpublic: 1543e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {} 1553e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {} 1562710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME 157*585a3cc3SDimitry Andric length_error(const length_error&) _NOEXCEPT = default; 158a62f2899SHoward Hinnant virtual ~length_error() _NOEXCEPT; 1592710d8e1SEric Fiselier#endif 1603e519524SHoward Hinnant}; 1613e519524SHoward Hinnant 1623e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI out_of_range 1633e519524SHoward Hinnant : public logic_error 1643e519524SHoward Hinnant{ 1653e519524SHoward Hinnantpublic: 1663e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {} 1673e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {} 1683e519524SHoward Hinnant 1692710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME 170*585a3cc3SDimitry Andric out_of_range(const out_of_range&) _NOEXCEPT = default; 171a62f2899SHoward Hinnant virtual ~out_of_range() _NOEXCEPT; 1722710d8e1SEric Fiselier#endif 1733e519524SHoward Hinnant}; 1743e519524SHoward Hinnant 1753e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI range_error 1763e519524SHoward Hinnant : public runtime_error 1773e519524SHoward Hinnant{ 1783e519524SHoward Hinnantpublic: 1793e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {} 1803e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {} 1813e519524SHoward Hinnant 1822710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME 183*585a3cc3SDimitry Andric range_error(const range_error&) _NOEXCEPT = default; 184a62f2899SHoward Hinnant virtual ~range_error() _NOEXCEPT; 1852710d8e1SEric Fiselier#endif 1863e519524SHoward Hinnant}; 1873e519524SHoward Hinnant 1883e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI overflow_error 1893e519524SHoward Hinnant : public runtime_error 1903e519524SHoward Hinnant{ 1913e519524SHoward Hinnantpublic: 1923e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {} 1933e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {} 1943e519524SHoward Hinnant 1952710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME 196*585a3cc3SDimitry Andric overflow_error(const overflow_error&) _NOEXCEPT = default; 197a62f2899SHoward Hinnant virtual ~overflow_error() _NOEXCEPT; 1982710d8e1SEric Fiselier#endif 1993e519524SHoward Hinnant}; 2003e519524SHoward Hinnant 2013e519524SHoward Hinnantclass _LIBCPP_EXCEPTION_ABI underflow_error 2023e519524SHoward Hinnant : public runtime_error 2033e519524SHoward Hinnant{ 2043e519524SHoward Hinnantpublic: 2053e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {} 2063e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {} 2073e519524SHoward Hinnant 2082710d8e1SEric Fiselier#ifndef _LIBCPP_ABI_VCRUNTIME 209*585a3cc3SDimitry Andric underflow_error(const underflow_error&) _NOEXCEPT = default; 210a62f2899SHoward Hinnant virtual ~underflow_error() _NOEXCEPT; 2112710d8e1SEric Fiselier#endif 2123e519524SHoward Hinnant}; 2133e519524SHoward Hinnant 2143e519524SHoward Hinnant} // std 2153e519524SHoward Hinnant 216d437fa5cSMarshall Clow_LIBCPP_BEGIN_NAMESPACE_STD 217d437fa5cSMarshall Clow 218d437fa5cSMarshall Clow// in the dylib 219d437fa5cSMarshall Clow_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*); 220d437fa5cSMarshall Clow 221dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 222d437fa5cSMarshall Clowvoid __throw_logic_error(const char*__msg) 223d437fa5cSMarshall Clow{ 224d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS 225d437fa5cSMarshall Clow throw logic_error(__msg); 226d437fa5cSMarshall Clow#else 227fd838227SEric Fiselier ((void)__msg); 228d437fa5cSMarshall Clow _VSTD::abort(); 229d437fa5cSMarshall Clow#endif 230d437fa5cSMarshall Clow} 231d437fa5cSMarshall Clow 232dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 233d437fa5cSMarshall Clowvoid __throw_domain_error(const char*__msg) 234d437fa5cSMarshall Clow{ 235d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS 236d437fa5cSMarshall Clow throw domain_error(__msg); 237d437fa5cSMarshall Clow#else 238fd838227SEric Fiselier ((void)__msg); 239d437fa5cSMarshall Clow _VSTD::abort(); 240d437fa5cSMarshall Clow#endif 241d437fa5cSMarshall Clow} 242d437fa5cSMarshall Clow 243dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 244d437fa5cSMarshall Clowvoid __throw_invalid_argument(const char*__msg) 245d437fa5cSMarshall Clow{ 246d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS 247d437fa5cSMarshall Clow throw invalid_argument(__msg); 248d437fa5cSMarshall Clow#else 249fd838227SEric Fiselier ((void)__msg); 250d437fa5cSMarshall Clow _VSTD::abort(); 251d437fa5cSMarshall Clow#endif 252d437fa5cSMarshall Clow} 253d437fa5cSMarshall Clow 254dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 255d437fa5cSMarshall Clowvoid __throw_length_error(const char*__msg) 256d437fa5cSMarshall Clow{ 257d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS 258d437fa5cSMarshall Clow throw length_error(__msg); 259d437fa5cSMarshall Clow#else 260fd838227SEric Fiselier ((void)__msg); 261d437fa5cSMarshall Clow _VSTD::abort(); 262d437fa5cSMarshall Clow#endif 263d437fa5cSMarshall Clow} 264d437fa5cSMarshall Clow 265dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 266d437fa5cSMarshall Clowvoid __throw_out_of_range(const char*__msg) 267d437fa5cSMarshall Clow{ 268d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS 269d437fa5cSMarshall Clow throw out_of_range(__msg); 270d437fa5cSMarshall Clow#else 271fd838227SEric Fiselier ((void)__msg); 272d437fa5cSMarshall Clow _VSTD::abort(); 273d437fa5cSMarshall Clow#endif 274d437fa5cSMarshall Clow} 275d437fa5cSMarshall Clow 276dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 277d437fa5cSMarshall Clowvoid __throw_range_error(const char*__msg) 278d437fa5cSMarshall Clow{ 279d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS 280d437fa5cSMarshall Clow throw range_error(__msg); 281d437fa5cSMarshall Clow#else 282fd838227SEric Fiselier ((void)__msg); 283d437fa5cSMarshall Clow _VSTD::abort(); 284d437fa5cSMarshall Clow#endif 285d437fa5cSMarshall Clow} 286d437fa5cSMarshall Clow 287dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 288d437fa5cSMarshall Clowvoid __throw_overflow_error(const char*__msg) 289d437fa5cSMarshall Clow{ 290d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS 291d437fa5cSMarshall Clow throw overflow_error(__msg); 292d437fa5cSMarshall Clow#else 293fd838227SEric Fiselier ((void)__msg); 294d437fa5cSMarshall Clow _VSTD::abort(); 295d437fa5cSMarshall Clow#endif 296d437fa5cSMarshall Clow} 297d437fa5cSMarshall Clow 298dc7200b4SLouis Dionne_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 299d437fa5cSMarshall Clowvoid __throw_underflow_error(const char*__msg) 300d437fa5cSMarshall Clow{ 301d437fa5cSMarshall Clow#ifndef _LIBCPP_NO_EXCEPTIONS 302d437fa5cSMarshall Clow throw underflow_error(__msg); 303d437fa5cSMarshall Clow#else 304fd838227SEric Fiselier ((void)__msg); 305d437fa5cSMarshall Clow _VSTD::abort(); 306d437fa5cSMarshall Clow#endif 307d437fa5cSMarshall Clow} 308d437fa5cSMarshall Clow 309d437fa5cSMarshall Clow_LIBCPP_END_NAMESPACE_STD 310d437fa5cSMarshall Clow 3113e519524SHoward Hinnant#endif // _LIBCPP_STDEXCEPT 312