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