blob: 4218b1398d85b466962348f8c052b98824affaed [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- stdexcept --------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_STDEXCEPT
12#define _LIBCPP_STDEXCEPT
13
14/*
15 stdexcept synopsis
16
17namespace std
18{
19
20class logic_error;
21 class domain_error;
22 class invalid_argument;
23 class length_error;
24 class out_of_range;
25class runtime_error;
26 class range_error;
27 class overflow_error;
28 class underflow_error;
29
30for each class xxx_error:
31
32class xxx_error : public exception // at least indirectly
33{
34public:
35 explicit xxx_error(const string& what_arg);
Howard Hinnant1e15fd12011-05-26 19:48:01 +000036 explicit xxx_error(const char* what_arg);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000037
Howard Hinnant1e15fd12011-05-26 19:48:01 +000038 virtual const char* what() const noexcept // returns what_arg
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000039};
40
41} // std
42
43*/
44
45#include <__config>
46#include <exception>
47#include <iosfwd> // for string forward decl
48
Howard Hinnant08e17472011-10-17 20:05:10 +000049#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000050#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +000051#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000052
Joerg Sonnenberger55622072014-04-30 19:54:11 +000053#ifndef _LIBCPP___REFSTRING
54_LIBCPP_BEGIN_NAMESPACE_STD
55class _LIBCPP_HIDDEN __libcpp_refstring {
Eric Fiselier566bcb42016-04-21 22:54:21 +000056#ifdef __clang__
57 const char *__imp_ __attribute__((__unused__)); // only clang emits a warning
58#else
59 const char *__imp_;
60#endif
Joerg Sonnenberger55622072014-04-30 19:54:11 +000061};
62_LIBCPP_END_NAMESPACE_STD
63#endif
64
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000065namespace std // purposefully not using versioning namespace
66{
67
68class _LIBCPP_EXCEPTION_ABI logic_error
69 : public exception
70{
71private:
Joerg Sonnenberger55622072014-04-30 19:54:11 +000072 _VSTD::__libcpp_refstring __imp_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000073public:
74 explicit logic_error(const string&);
75 explicit logic_error(const char*);
76
Howard Hinnant1e15fd12011-05-26 19:48:01 +000077 logic_error(const logic_error&) _NOEXCEPT;
78 logic_error& operator=(const logic_error&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000079
Howard Hinnant1e15fd12011-05-26 19:48:01 +000080 virtual ~logic_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000081
Howard Hinnant1e15fd12011-05-26 19:48:01 +000082 virtual const char* what() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000083};
84
85class _LIBCPP_EXCEPTION_ABI runtime_error
86 : public exception
87{
88private:
Joerg Sonnenberger55622072014-04-30 19:54:11 +000089 _VSTD::__libcpp_refstring __imp_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000090public:
91 explicit runtime_error(const string&);
92 explicit runtime_error(const char*);
93
Howard Hinnant1e15fd12011-05-26 19:48:01 +000094 runtime_error(const runtime_error&) _NOEXCEPT;
95 runtime_error& operator=(const runtime_error&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000096
Howard Hinnant1e15fd12011-05-26 19:48:01 +000097 virtual ~runtime_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000098
Howard Hinnant1e15fd12011-05-26 19:48:01 +000099 virtual const char* what() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000100};
101
102class _LIBCPP_EXCEPTION_ABI domain_error
103 : public logic_error
104{
105public:
106 _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {}
107 _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {}
108
Howard Hinnant1e15fd12011-05-26 19:48:01 +0000109 virtual ~domain_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000110};
111
112class _LIBCPP_EXCEPTION_ABI invalid_argument
113 : public logic_error
114{
115public:
116 _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {}
117 _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {}
118
Howard Hinnant1e15fd12011-05-26 19:48:01 +0000119 virtual ~invalid_argument() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120};
121
122class _LIBCPP_EXCEPTION_ABI length_error
123 : public logic_error
124{
125public:
126 _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {}
127 _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {}
128
Howard Hinnant1e15fd12011-05-26 19:48:01 +0000129 virtual ~length_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000130};
131
132class _LIBCPP_EXCEPTION_ABI out_of_range
133 : public logic_error
134{
135public:
136 _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {}
137 _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {}
138
Howard Hinnant1e15fd12011-05-26 19:48:01 +0000139 virtual ~out_of_range() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000140};
141
142class _LIBCPP_EXCEPTION_ABI range_error
143 : public runtime_error
144{
145public:
146 _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {}
147 _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {}
148
Howard Hinnant1e15fd12011-05-26 19:48:01 +0000149 virtual ~range_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000150};
151
152class _LIBCPP_EXCEPTION_ABI overflow_error
153 : public runtime_error
154{
155public:
156 _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {}
157 _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {}
158
Howard Hinnant1e15fd12011-05-26 19:48:01 +0000159 virtual ~overflow_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000160};
161
162class _LIBCPP_EXCEPTION_ABI underflow_error
163 : public runtime_error
164{
165public:
166 _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {}
167 _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {}
168
Howard Hinnant1e15fd12011-05-26 19:48:01 +0000169 virtual ~underflow_error() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000170};
171
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000172} // std
173
174#endif // _LIBCPP_STDEXCEPT