17a984708SDavid Chisnall// -*- C++ -*- 27a984708SDavid Chisnall//===--------------------------- stdexcept --------------------------------===// 37a984708SDavid Chisnall// 47a984708SDavid Chisnall// The LLVM Compiler Infrastructure 57a984708SDavid Chisnall// 67a984708SDavid Chisnall// This file is dual licensed under the MIT and the University of Illinois Open 77a984708SDavid Chisnall// Source Licenses. See LICENSE.TXT for details. 87a984708SDavid Chisnall// 97a984708SDavid Chisnall//===----------------------------------------------------------------------===// 107a984708SDavid Chisnall 117a984708SDavid Chisnall#ifndef _LIBCPP_STDEXCEPT 127a984708SDavid Chisnall#define _LIBCPP_STDEXCEPT 137a984708SDavid Chisnall 147a984708SDavid Chisnall/* 157a984708SDavid Chisnall stdexcept synopsis 167a984708SDavid Chisnall 177a984708SDavid Chisnallnamespace std 187a984708SDavid Chisnall{ 197a984708SDavid Chisnall 207a984708SDavid Chisnallclass logic_error; 217a984708SDavid Chisnall class domain_error; 227a984708SDavid Chisnall class invalid_argument; 237a984708SDavid Chisnall class length_error; 247a984708SDavid Chisnall class out_of_range; 257a984708SDavid Chisnallclass runtime_error; 267a984708SDavid Chisnall class range_error; 277a984708SDavid Chisnall class overflow_error; 287a984708SDavid Chisnall class underflow_error; 297a984708SDavid Chisnall 307a984708SDavid Chisnallfor each class xxx_error: 317a984708SDavid Chisnall 327a984708SDavid Chisnallclass xxx_error : public exception // at least indirectly 337a984708SDavid Chisnall{ 347a984708SDavid Chisnallpublic: 357a984708SDavid Chisnall explicit xxx_error(const string& what_arg); 367a984708SDavid Chisnall explicit xxx_error(const char* what_arg); 377a984708SDavid Chisnall 387a984708SDavid Chisnall virtual const char* what() const noexcept // returns what_arg 397a984708SDavid Chisnall}; 407a984708SDavid Chisnall 417a984708SDavid Chisnall} // std 427a984708SDavid Chisnall 437a984708SDavid Chisnall*/ 447a984708SDavid Chisnall 457a984708SDavid Chisnall#include <__config> 467a984708SDavid Chisnall#include <exception> 477a984708SDavid Chisnall#include <iosfwd> // for string forward decl 48aed8d94eSDimitry Andric#ifdef _LIBCPP_NO_EXCEPTIONS 49aed8d94eSDimitry Andric#include <cstdlib> 50aed8d94eSDimitry Andric#endif 517a984708SDavid Chisnall 527a984708SDavid Chisnall#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 537a984708SDavid Chisnall#pragma GCC system_header 547a984708SDavid Chisnall#endif 557a984708SDavid Chisnall 56d72607e9SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 57aed8d94eSDimitry Andric 58aed8d94eSDimitry Andricclass _LIBCPP_HIDDEN __libcpp_refstring 59aed8d94eSDimitry Andric{ 607c82a1ecSDimitry Andric const char* __imp_; 61aed8d94eSDimitry Andric 62aed8d94eSDimitry Andric bool __uses_refcount() const; 63aed8d94eSDimitry Andricpublic: 64f9448bf3SDimitry Andric explicit __libcpp_refstring(const char* __msg); 65f9448bf3SDimitry Andric __libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT; 66f9448bf3SDimitry Andric __libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT; 67aed8d94eSDimitry Andric ~__libcpp_refstring(); 68aed8d94eSDimitry Andric 69aed8d94eSDimitry Andric const char* c_str() const _NOEXCEPT {return __imp_;} 70d72607e9SDimitry Andric}; 71aed8d94eSDimitry Andric 72d72607e9SDimitry Andric_LIBCPP_END_NAMESPACE_STD 73d72607e9SDimitry Andric 747a984708SDavid Chisnallnamespace std // purposefully not using versioning namespace 757a984708SDavid Chisnall{ 767a984708SDavid Chisnall 777a984708SDavid Chisnallclass _LIBCPP_EXCEPTION_ABI logic_error 787a984708SDavid Chisnall : public exception 797a984708SDavid Chisnall{ 807a984708SDavid Chisnallprivate: 81d72607e9SDimitry Andric _VSTD::__libcpp_refstring __imp_; 827a984708SDavid Chisnallpublic: 837a984708SDavid Chisnall explicit logic_error(const string&); 847a984708SDavid Chisnall explicit logic_error(const char*); 857a984708SDavid Chisnall 867a984708SDavid Chisnall logic_error(const logic_error&) _NOEXCEPT; 877a984708SDavid Chisnall logic_error& operator=(const logic_error&) _NOEXCEPT; 887a984708SDavid Chisnall 897a984708SDavid Chisnall virtual ~logic_error() _NOEXCEPT; 907a984708SDavid Chisnall 917a984708SDavid Chisnall virtual const char* what() const _NOEXCEPT; 927a984708SDavid Chisnall}; 937a984708SDavid Chisnall 947a984708SDavid Chisnallclass _LIBCPP_EXCEPTION_ABI runtime_error 957a984708SDavid Chisnall : public exception 967a984708SDavid Chisnall{ 977a984708SDavid Chisnallprivate: 98d72607e9SDimitry Andric _VSTD::__libcpp_refstring __imp_; 997a984708SDavid Chisnallpublic: 1007a984708SDavid Chisnall explicit runtime_error(const string&); 1017a984708SDavid Chisnall explicit runtime_error(const char*); 1027a984708SDavid Chisnall 1037a984708SDavid Chisnall runtime_error(const runtime_error&) _NOEXCEPT; 1047a984708SDavid Chisnall runtime_error& operator=(const runtime_error&) _NOEXCEPT; 1057a984708SDavid Chisnall 1067a984708SDavid Chisnall virtual ~runtime_error() _NOEXCEPT; 1077a984708SDavid Chisnall 1087a984708SDavid Chisnall virtual const char* what() const _NOEXCEPT; 1097a984708SDavid Chisnall}; 1107a984708SDavid Chisnall 1117a984708SDavid Chisnallclass _LIBCPP_EXCEPTION_ABI domain_error 1127a984708SDavid Chisnall : public logic_error 1137a984708SDavid Chisnall{ 1147a984708SDavid Chisnallpublic: 1157a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {} 1167a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {} 1177a984708SDavid Chisnall 1187a984708SDavid Chisnall virtual ~domain_error() _NOEXCEPT; 1197a984708SDavid Chisnall}; 1207a984708SDavid Chisnall 1217a984708SDavid Chisnallclass _LIBCPP_EXCEPTION_ABI invalid_argument 1227a984708SDavid Chisnall : public logic_error 1237a984708SDavid Chisnall{ 1247a984708SDavid Chisnallpublic: 1257a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {} 1267a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {} 1277a984708SDavid Chisnall 1287a984708SDavid Chisnall virtual ~invalid_argument() _NOEXCEPT; 1297a984708SDavid Chisnall}; 1307a984708SDavid Chisnall 1317a984708SDavid Chisnallclass _LIBCPP_EXCEPTION_ABI length_error 1327a984708SDavid Chisnall : public logic_error 1337a984708SDavid Chisnall{ 1347a984708SDavid Chisnallpublic: 1357a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {} 1367a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {} 1377a984708SDavid Chisnall 1387a984708SDavid Chisnall virtual ~length_error() _NOEXCEPT; 1397a984708SDavid Chisnall}; 1407a984708SDavid Chisnall 1417a984708SDavid Chisnallclass _LIBCPP_EXCEPTION_ABI out_of_range 1427a984708SDavid Chisnall : public logic_error 1437a984708SDavid Chisnall{ 1447a984708SDavid Chisnallpublic: 1457a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {} 1467a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {} 1477a984708SDavid Chisnall 1487a984708SDavid Chisnall virtual ~out_of_range() _NOEXCEPT; 1497a984708SDavid Chisnall}; 1507a984708SDavid Chisnall 1517a984708SDavid Chisnallclass _LIBCPP_EXCEPTION_ABI range_error 1527a984708SDavid Chisnall : public runtime_error 1537a984708SDavid Chisnall{ 1547a984708SDavid Chisnallpublic: 1557a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {} 1567a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {} 1577a984708SDavid Chisnall 1587a984708SDavid Chisnall virtual ~range_error() _NOEXCEPT; 1597a984708SDavid Chisnall}; 1607a984708SDavid Chisnall 1617a984708SDavid Chisnallclass _LIBCPP_EXCEPTION_ABI overflow_error 1627a984708SDavid Chisnall : public runtime_error 1637a984708SDavid Chisnall{ 1647a984708SDavid Chisnallpublic: 1657a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {} 1667a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {} 1677a984708SDavid Chisnall 1687a984708SDavid Chisnall virtual ~overflow_error() _NOEXCEPT; 1697a984708SDavid Chisnall}; 1707a984708SDavid Chisnall 1717a984708SDavid Chisnallclass _LIBCPP_EXCEPTION_ABI underflow_error 1727a984708SDavid Chisnall : public runtime_error 1737a984708SDavid Chisnall{ 1747a984708SDavid Chisnallpublic: 1757a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {} 1767a984708SDavid Chisnall _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {} 1777a984708SDavid Chisnall 1787a984708SDavid Chisnall virtual ~underflow_error() _NOEXCEPT; 1797a984708SDavid Chisnall}; 1807a984708SDavid Chisnall 1817a984708SDavid Chisnall} // std 1827a984708SDavid Chisnall 183aed8d94eSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 184aed8d94eSDimitry Andric 185aed8d94eSDimitry Andric// in the dylib 186aed8d94eSDimitry Andric_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*); 187aed8d94eSDimitry Andric 188*4ba319b5SDimitry Andric_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 189aed8d94eSDimitry Andricvoid __throw_logic_error(const char*__msg) 190aed8d94eSDimitry Andric{ 191aed8d94eSDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 192aed8d94eSDimitry Andric throw logic_error(__msg); 193aed8d94eSDimitry Andric#else 194aed8d94eSDimitry Andric ((void)__msg); 195aed8d94eSDimitry Andric _VSTD::abort(); 196aed8d94eSDimitry Andric#endif 197aed8d94eSDimitry Andric} 198aed8d94eSDimitry Andric 199*4ba319b5SDimitry Andric_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 200aed8d94eSDimitry Andricvoid __throw_domain_error(const char*__msg) 201aed8d94eSDimitry Andric{ 202aed8d94eSDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 203aed8d94eSDimitry Andric throw domain_error(__msg); 204aed8d94eSDimitry Andric#else 205aed8d94eSDimitry Andric ((void)__msg); 206aed8d94eSDimitry Andric _VSTD::abort(); 207aed8d94eSDimitry Andric#endif 208aed8d94eSDimitry Andric} 209aed8d94eSDimitry Andric 210*4ba319b5SDimitry Andric_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 211aed8d94eSDimitry Andricvoid __throw_invalid_argument(const char*__msg) 212aed8d94eSDimitry Andric{ 213aed8d94eSDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 214aed8d94eSDimitry Andric throw invalid_argument(__msg); 215aed8d94eSDimitry Andric#else 216aed8d94eSDimitry Andric ((void)__msg); 217aed8d94eSDimitry Andric _VSTD::abort(); 218aed8d94eSDimitry Andric#endif 219aed8d94eSDimitry Andric} 220aed8d94eSDimitry Andric 221*4ba319b5SDimitry Andric_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 222aed8d94eSDimitry Andricvoid __throw_length_error(const char*__msg) 223aed8d94eSDimitry Andric{ 224aed8d94eSDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 225aed8d94eSDimitry Andric throw length_error(__msg); 226aed8d94eSDimitry Andric#else 227aed8d94eSDimitry Andric ((void)__msg); 228aed8d94eSDimitry Andric _VSTD::abort(); 229aed8d94eSDimitry Andric#endif 230aed8d94eSDimitry Andric} 231aed8d94eSDimitry Andric 232*4ba319b5SDimitry Andric_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 233aed8d94eSDimitry Andricvoid __throw_out_of_range(const char*__msg) 234aed8d94eSDimitry Andric{ 235aed8d94eSDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 236aed8d94eSDimitry Andric throw out_of_range(__msg); 237aed8d94eSDimitry Andric#else 238aed8d94eSDimitry Andric ((void)__msg); 239aed8d94eSDimitry Andric _VSTD::abort(); 240aed8d94eSDimitry Andric#endif 241aed8d94eSDimitry Andric} 242aed8d94eSDimitry Andric 243*4ba319b5SDimitry Andric_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 244aed8d94eSDimitry Andricvoid __throw_range_error(const char*__msg) 245aed8d94eSDimitry Andric{ 246aed8d94eSDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 247aed8d94eSDimitry Andric throw range_error(__msg); 248aed8d94eSDimitry Andric#else 249aed8d94eSDimitry Andric ((void)__msg); 250aed8d94eSDimitry Andric _VSTD::abort(); 251aed8d94eSDimitry Andric#endif 252aed8d94eSDimitry Andric} 253aed8d94eSDimitry Andric 254*4ba319b5SDimitry Andric_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 255aed8d94eSDimitry Andricvoid __throw_overflow_error(const char*__msg) 256aed8d94eSDimitry Andric{ 257aed8d94eSDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 258aed8d94eSDimitry Andric throw overflow_error(__msg); 259aed8d94eSDimitry Andric#else 260aed8d94eSDimitry Andric ((void)__msg); 261aed8d94eSDimitry Andric _VSTD::abort(); 262aed8d94eSDimitry Andric#endif 263aed8d94eSDimitry Andric} 264aed8d94eSDimitry Andric 265*4ba319b5SDimitry Andric_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 266aed8d94eSDimitry Andricvoid __throw_underflow_error(const char*__msg) 267aed8d94eSDimitry Andric{ 268aed8d94eSDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 269aed8d94eSDimitry Andric throw underflow_error(__msg); 270aed8d94eSDimitry Andric#else 271aed8d94eSDimitry Andric ((void)__msg); 272aed8d94eSDimitry Andric _VSTD::abort(); 273aed8d94eSDimitry Andric#endif 274aed8d94eSDimitry Andric} 275aed8d94eSDimitry Andric 276aed8d94eSDimitry Andric_LIBCPP_END_NAMESPACE_STD 277aed8d94eSDimitry Andric 2787a984708SDavid Chisnall#endif // _LIBCPP_STDEXCEPT 279