1*4d6fc14bSjoerg// -*- C++ -*- 2*4d6fc14bSjoerg//===--------------------------- stdexcept --------------------------------===// 3*4d6fc14bSjoerg// 4*4d6fc14bSjoerg// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5*4d6fc14bSjoerg// See https://llvm.org/LICENSE.txt for license information. 6*4d6fc14bSjoerg// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7*4d6fc14bSjoerg// 8*4d6fc14bSjoerg//===----------------------------------------------------------------------===// 9*4d6fc14bSjoerg 10*4d6fc14bSjoerg#ifndef _LIBCPP_STDEXCEPT 11*4d6fc14bSjoerg#define _LIBCPP_STDEXCEPT 12*4d6fc14bSjoerg 13*4d6fc14bSjoerg/* 14*4d6fc14bSjoerg stdexcept synopsis 15*4d6fc14bSjoerg 16*4d6fc14bSjoergnamespace std 17*4d6fc14bSjoerg{ 18*4d6fc14bSjoerg 19*4d6fc14bSjoergclass logic_error; 20*4d6fc14bSjoerg class domain_error; 21*4d6fc14bSjoerg class invalid_argument; 22*4d6fc14bSjoerg class length_error; 23*4d6fc14bSjoerg class out_of_range; 24*4d6fc14bSjoergclass runtime_error; 25*4d6fc14bSjoerg class range_error; 26*4d6fc14bSjoerg class overflow_error; 27*4d6fc14bSjoerg class underflow_error; 28*4d6fc14bSjoerg 29*4d6fc14bSjoergfor each class xxx_error: 30*4d6fc14bSjoerg 31*4d6fc14bSjoergclass xxx_error : public exception // at least indirectly 32*4d6fc14bSjoerg{ 33*4d6fc14bSjoergpublic: 34*4d6fc14bSjoerg explicit xxx_error(const string& what_arg); 35*4d6fc14bSjoerg explicit xxx_error(const char* what_arg); 36*4d6fc14bSjoerg 37*4d6fc14bSjoerg virtual const char* what() const noexcept // returns what_arg 38*4d6fc14bSjoerg}; 39*4d6fc14bSjoerg 40*4d6fc14bSjoerg} // std 41*4d6fc14bSjoerg 42*4d6fc14bSjoerg*/ 43*4d6fc14bSjoerg 44*4d6fc14bSjoerg#include <__config> 45*4d6fc14bSjoerg#include <cstdlib> 46*4d6fc14bSjoerg#include <exception> 47*4d6fc14bSjoerg#include <iosfwd> // for string forward decl 48*4d6fc14bSjoerg 49*4d6fc14bSjoerg#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 50*4d6fc14bSjoerg#pragma GCC system_header 51*4d6fc14bSjoerg#endif 52*4d6fc14bSjoerg 53*4d6fc14bSjoerg_LIBCPP_BEGIN_NAMESPACE_STD 54*4d6fc14bSjoerg 55*4d6fc14bSjoerg#ifndef _LIBCPP_ABI_VCRUNTIME 56*4d6fc14bSjoergclass _LIBCPP_HIDDEN __libcpp_refstring 57*4d6fc14bSjoerg{ 58*4d6fc14bSjoerg const char* __imp_; 59*4d6fc14bSjoerg 60*4d6fc14bSjoerg bool __uses_refcount() const; 61*4d6fc14bSjoergpublic: 62*4d6fc14bSjoerg explicit __libcpp_refstring(const char* __msg); 63*4d6fc14bSjoerg __libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT; 64*4d6fc14bSjoerg __libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT; 65*4d6fc14bSjoerg ~__libcpp_refstring(); 66*4d6fc14bSjoerg 67*4d6fc14bSjoerg const char* c_str() const _NOEXCEPT {return __imp_;} 68*4d6fc14bSjoerg}; 69*4d6fc14bSjoerg#endif // !_LIBCPP_ABI_VCRUNTIME 70*4d6fc14bSjoerg 71*4d6fc14bSjoerg_LIBCPP_END_NAMESPACE_STD 72*4d6fc14bSjoerg 73*4d6fc14bSjoergnamespace std // purposefully not using versioning namespace 74*4d6fc14bSjoerg{ 75*4d6fc14bSjoerg 76*4d6fc14bSjoergclass _LIBCPP_EXCEPTION_ABI logic_error 77*4d6fc14bSjoerg : public exception 78*4d6fc14bSjoerg{ 79*4d6fc14bSjoerg#ifndef _LIBCPP_ABI_VCRUNTIME 80*4d6fc14bSjoergprivate: 81*4d6fc14bSjoerg _VSTD::__libcpp_refstring __imp_; 82*4d6fc14bSjoergpublic: 83*4d6fc14bSjoerg explicit logic_error(const string&); 84*4d6fc14bSjoerg explicit logic_error(const char*); 85*4d6fc14bSjoerg 86*4d6fc14bSjoerg logic_error(const logic_error&) _NOEXCEPT; 87*4d6fc14bSjoerg logic_error& operator=(const logic_error&) _NOEXCEPT; 88*4d6fc14bSjoerg 89*4d6fc14bSjoerg virtual ~logic_error() _NOEXCEPT; 90*4d6fc14bSjoerg 91*4d6fc14bSjoerg virtual const char* what() const _NOEXCEPT; 92*4d6fc14bSjoerg#else 93*4d6fc14bSjoergpublic: 94*4d6fc14bSjoerg explicit logic_error(const _VSTD::string&); // Symbol uses versioned std::string 95*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY explicit logic_error(const char* __s) : exception(__s) {} 96*4d6fc14bSjoerg#endif 97*4d6fc14bSjoerg}; 98*4d6fc14bSjoerg 99*4d6fc14bSjoergclass _LIBCPP_EXCEPTION_ABI runtime_error 100*4d6fc14bSjoerg : public exception 101*4d6fc14bSjoerg{ 102*4d6fc14bSjoerg#ifndef _LIBCPP_ABI_VCRUNTIME 103*4d6fc14bSjoergprivate: 104*4d6fc14bSjoerg _VSTD::__libcpp_refstring __imp_; 105*4d6fc14bSjoergpublic: 106*4d6fc14bSjoerg explicit runtime_error(const string&); 107*4d6fc14bSjoerg explicit runtime_error(const char*); 108*4d6fc14bSjoerg 109*4d6fc14bSjoerg runtime_error(const runtime_error&) _NOEXCEPT; 110*4d6fc14bSjoerg runtime_error& operator=(const runtime_error&) _NOEXCEPT; 111*4d6fc14bSjoerg 112*4d6fc14bSjoerg virtual ~runtime_error() _NOEXCEPT; 113*4d6fc14bSjoerg 114*4d6fc14bSjoerg virtual const char* what() const _NOEXCEPT; 115*4d6fc14bSjoerg#else 116*4d6fc14bSjoergpublic: 117*4d6fc14bSjoerg explicit runtime_error(const _VSTD::string&); // Symbol uses versioned std::string 118*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY explicit runtime_error(const char* __s) : exception(__s) {} 119*4d6fc14bSjoerg#endif // _LIBCPP_ABI_VCRUNTIME 120*4d6fc14bSjoerg}; 121*4d6fc14bSjoerg 122*4d6fc14bSjoergclass _LIBCPP_EXCEPTION_ABI domain_error 123*4d6fc14bSjoerg : public logic_error 124*4d6fc14bSjoerg{ 125*4d6fc14bSjoergpublic: 126*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {} 127*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {} 128*4d6fc14bSjoerg 129*4d6fc14bSjoerg#ifndef _LIBCPP_ABI_VCRUNTIME 130*4d6fc14bSjoerg domain_error(const domain_error&) _NOEXCEPT = default; 131*4d6fc14bSjoerg virtual ~domain_error() _NOEXCEPT; 132*4d6fc14bSjoerg#endif 133*4d6fc14bSjoerg}; 134*4d6fc14bSjoerg 135*4d6fc14bSjoergclass _LIBCPP_EXCEPTION_ABI invalid_argument 136*4d6fc14bSjoerg : public logic_error 137*4d6fc14bSjoerg{ 138*4d6fc14bSjoergpublic: 139*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {} 140*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {} 141*4d6fc14bSjoerg 142*4d6fc14bSjoerg#ifndef _LIBCPP_ABI_VCRUNTIME 143*4d6fc14bSjoerg invalid_argument(const invalid_argument&) _NOEXCEPT = default; 144*4d6fc14bSjoerg virtual ~invalid_argument() _NOEXCEPT; 145*4d6fc14bSjoerg#endif 146*4d6fc14bSjoerg}; 147*4d6fc14bSjoerg 148*4d6fc14bSjoergclass _LIBCPP_EXCEPTION_ABI length_error 149*4d6fc14bSjoerg : public logic_error 150*4d6fc14bSjoerg{ 151*4d6fc14bSjoergpublic: 152*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {} 153*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {} 154*4d6fc14bSjoerg#ifndef _LIBCPP_ABI_VCRUNTIME 155*4d6fc14bSjoerg length_error(const length_error&) _NOEXCEPT = default; 156*4d6fc14bSjoerg virtual ~length_error() _NOEXCEPT; 157*4d6fc14bSjoerg#endif 158*4d6fc14bSjoerg}; 159*4d6fc14bSjoerg 160*4d6fc14bSjoergclass _LIBCPP_EXCEPTION_ABI out_of_range 161*4d6fc14bSjoerg : public logic_error 162*4d6fc14bSjoerg{ 163*4d6fc14bSjoergpublic: 164*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {} 165*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {} 166*4d6fc14bSjoerg 167*4d6fc14bSjoerg#ifndef _LIBCPP_ABI_VCRUNTIME 168*4d6fc14bSjoerg out_of_range(const out_of_range&) _NOEXCEPT = default; 169*4d6fc14bSjoerg virtual ~out_of_range() _NOEXCEPT; 170*4d6fc14bSjoerg#endif 171*4d6fc14bSjoerg}; 172*4d6fc14bSjoerg 173*4d6fc14bSjoergclass _LIBCPP_EXCEPTION_ABI range_error 174*4d6fc14bSjoerg : public runtime_error 175*4d6fc14bSjoerg{ 176*4d6fc14bSjoergpublic: 177*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {} 178*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {} 179*4d6fc14bSjoerg 180*4d6fc14bSjoerg#ifndef _LIBCPP_ABI_VCRUNTIME 181*4d6fc14bSjoerg range_error(const range_error&) _NOEXCEPT = default; 182*4d6fc14bSjoerg virtual ~range_error() _NOEXCEPT; 183*4d6fc14bSjoerg#endif 184*4d6fc14bSjoerg}; 185*4d6fc14bSjoerg 186*4d6fc14bSjoergclass _LIBCPP_EXCEPTION_ABI overflow_error 187*4d6fc14bSjoerg : public runtime_error 188*4d6fc14bSjoerg{ 189*4d6fc14bSjoergpublic: 190*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {} 191*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {} 192*4d6fc14bSjoerg 193*4d6fc14bSjoerg#ifndef _LIBCPP_ABI_VCRUNTIME 194*4d6fc14bSjoerg overflow_error(const overflow_error&) _NOEXCEPT = default; 195*4d6fc14bSjoerg virtual ~overflow_error() _NOEXCEPT; 196*4d6fc14bSjoerg#endif 197*4d6fc14bSjoerg}; 198*4d6fc14bSjoerg 199*4d6fc14bSjoergclass _LIBCPP_EXCEPTION_ABI underflow_error 200*4d6fc14bSjoerg : public runtime_error 201*4d6fc14bSjoerg{ 202*4d6fc14bSjoergpublic: 203*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {} 204*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {} 205*4d6fc14bSjoerg 206*4d6fc14bSjoerg#ifndef _LIBCPP_ABI_VCRUNTIME 207*4d6fc14bSjoerg underflow_error(const underflow_error&) _NOEXCEPT = default; 208*4d6fc14bSjoerg virtual ~underflow_error() _NOEXCEPT; 209*4d6fc14bSjoerg#endif 210*4d6fc14bSjoerg}; 211*4d6fc14bSjoerg 212*4d6fc14bSjoerg} // std 213*4d6fc14bSjoerg 214*4d6fc14bSjoerg_LIBCPP_BEGIN_NAMESPACE_STD 215*4d6fc14bSjoerg 216*4d6fc14bSjoerg// in the dylib 217*4d6fc14bSjoerg_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*); 218*4d6fc14bSjoerg 219*4d6fc14bSjoerg_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 220*4d6fc14bSjoergvoid __throw_logic_error(const char*__msg) 221*4d6fc14bSjoerg{ 222*4d6fc14bSjoerg#ifndef _LIBCPP_NO_EXCEPTIONS 223*4d6fc14bSjoerg throw logic_error(__msg); 224*4d6fc14bSjoerg#else 225*4d6fc14bSjoerg ((void)__msg); 226*4d6fc14bSjoerg _VSTD::abort(); 227*4d6fc14bSjoerg#endif 228*4d6fc14bSjoerg} 229*4d6fc14bSjoerg 230*4d6fc14bSjoerg_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 231*4d6fc14bSjoergvoid __throw_domain_error(const char*__msg) 232*4d6fc14bSjoerg{ 233*4d6fc14bSjoerg#ifndef _LIBCPP_NO_EXCEPTIONS 234*4d6fc14bSjoerg throw domain_error(__msg); 235*4d6fc14bSjoerg#else 236*4d6fc14bSjoerg ((void)__msg); 237*4d6fc14bSjoerg _VSTD::abort(); 238*4d6fc14bSjoerg#endif 239*4d6fc14bSjoerg} 240*4d6fc14bSjoerg 241*4d6fc14bSjoerg_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 242*4d6fc14bSjoergvoid __throw_invalid_argument(const char*__msg) 243*4d6fc14bSjoerg{ 244*4d6fc14bSjoerg#ifndef _LIBCPP_NO_EXCEPTIONS 245*4d6fc14bSjoerg throw invalid_argument(__msg); 246*4d6fc14bSjoerg#else 247*4d6fc14bSjoerg ((void)__msg); 248*4d6fc14bSjoerg _VSTD::abort(); 249*4d6fc14bSjoerg#endif 250*4d6fc14bSjoerg} 251*4d6fc14bSjoerg 252*4d6fc14bSjoerg_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 253*4d6fc14bSjoergvoid __throw_length_error(const char*__msg) 254*4d6fc14bSjoerg{ 255*4d6fc14bSjoerg#ifndef _LIBCPP_NO_EXCEPTIONS 256*4d6fc14bSjoerg throw length_error(__msg); 257*4d6fc14bSjoerg#else 258*4d6fc14bSjoerg ((void)__msg); 259*4d6fc14bSjoerg _VSTD::abort(); 260*4d6fc14bSjoerg#endif 261*4d6fc14bSjoerg} 262*4d6fc14bSjoerg 263*4d6fc14bSjoerg_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 264*4d6fc14bSjoergvoid __throw_out_of_range(const char*__msg) 265*4d6fc14bSjoerg{ 266*4d6fc14bSjoerg#ifndef _LIBCPP_NO_EXCEPTIONS 267*4d6fc14bSjoerg throw out_of_range(__msg); 268*4d6fc14bSjoerg#else 269*4d6fc14bSjoerg ((void)__msg); 270*4d6fc14bSjoerg _VSTD::abort(); 271*4d6fc14bSjoerg#endif 272*4d6fc14bSjoerg} 273*4d6fc14bSjoerg 274*4d6fc14bSjoerg_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 275*4d6fc14bSjoergvoid __throw_range_error(const char*__msg) 276*4d6fc14bSjoerg{ 277*4d6fc14bSjoerg#ifndef _LIBCPP_NO_EXCEPTIONS 278*4d6fc14bSjoerg throw range_error(__msg); 279*4d6fc14bSjoerg#else 280*4d6fc14bSjoerg ((void)__msg); 281*4d6fc14bSjoerg _VSTD::abort(); 282*4d6fc14bSjoerg#endif 283*4d6fc14bSjoerg} 284*4d6fc14bSjoerg 285*4d6fc14bSjoerg_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 286*4d6fc14bSjoergvoid __throw_overflow_error(const char*__msg) 287*4d6fc14bSjoerg{ 288*4d6fc14bSjoerg#ifndef _LIBCPP_NO_EXCEPTIONS 289*4d6fc14bSjoerg throw overflow_error(__msg); 290*4d6fc14bSjoerg#else 291*4d6fc14bSjoerg ((void)__msg); 292*4d6fc14bSjoerg _VSTD::abort(); 293*4d6fc14bSjoerg#endif 294*4d6fc14bSjoerg} 295*4d6fc14bSjoerg 296*4d6fc14bSjoerg_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 297*4d6fc14bSjoergvoid __throw_underflow_error(const char*__msg) 298*4d6fc14bSjoerg{ 299*4d6fc14bSjoerg#ifndef _LIBCPP_NO_EXCEPTIONS 300*4d6fc14bSjoerg throw underflow_error(__msg); 301*4d6fc14bSjoerg#else 302*4d6fc14bSjoerg ((void)__msg); 303*4d6fc14bSjoerg _VSTD::abort(); 304*4d6fc14bSjoerg#endif 305*4d6fc14bSjoerg} 306*4d6fc14bSjoerg 307*4d6fc14bSjoerg_LIBCPP_END_NAMESPACE_STD 308*4d6fc14bSjoerg 309*4d6fc14bSjoerg#endif // _LIBCPP_STDEXCEPT 310