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