]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/std/stdexcept
PR libstdc++/36104 part four
[thirdparty/gcc.git] / libstdc++-v3 / include / std / stdexcept
1 // Standard exception classes -*- C++ -*-
2
3 // Copyright (C) 2001, 2002, 2005, 2007, 2009, 2010
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
20
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
25
26 /** @file include/stdexcept
27 * This is a Standard C++ Library header.
28 */
29
30 //
31 // ISO C++ 19.1 Exception classes
32 //
33
34 #ifndef _GLIBCXX_STDEXCEPT
35 #define _GLIBCXX_STDEXCEPT 1
36
37 #pragma GCC system_header
38
39 #include <exception>
40 #include <string>
41
42 namespace std _GLIBCXX_VISIBILITY(default)
43 {
44 _GLIBCXX_BEGIN_NAMESPACE_VERSION
45
46 /**
47 * @addtogroup exceptions
48 * @{
49 */
50
51 /** Logic errors represent problems in the internal logic of a program;
52 * in theory, these are preventable, and even detectable before the
53 * program runs (e.g., violations of class invariants).
54 * @brief One of two subclasses of exception.
55 */
56 class logic_error : public exception
57 {
58 string _M_msg;
59
60 public:
61 /** Takes a character string describing the error. */
62 explicit
63 logic_error(const string& __arg);
64
65 virtual
66 ~logic_error() throw();
67
68 /** Returns a C-style character string describing the general cause of
69 * the current error (the same string passed to the ctor). */
70 virtual const char*
71 what() const throw();
72 };
73
74 /** Thrown by the library, or by you, to report domain errors (domain in
75 * the mathematical sense). */
76 class domain_error : public logic_error
77 {
78 public:
79 explicit domain_error(const string& __arg);
80 };
81
82 /** Thrown to report invalid arguments to functions. */
83 class invalid_argument : public logic_error
84 {
85 public:
86 explicit invalid_argument(const string& __arg);
87 };
88
89 /** Thrown when an object is constructed that would exceed its maximum
90 * permitted size (e.g., a basic_string instance). */
91 class length_error : public logic_error
92 {
93 public:
94 explicit length_error(const string& __arg);
95 };
96
97 /** This represents an argument whose value is not within the expected
98 * range (e.g., boundary checks in basic_string). */
99 class out_of_range : public logic_error
100 {
101 public:
102 explicit out_of_range(const string& __arg);
103 };
104
105 /** Runtime errors represent problems outside the scope of a program;
106 * they cannot be easily predicted and can generally only be caught as
107 * the program executes.
108 * @brief One of two subclasses of exception.
109 */
110 class runtime_error : public exception
111 {
112 string _M_msg;
113
114 public:
115 /** Takes a character string describing the error. */
116 explicit
117 runtime_error(const string& __arg);
118
119 virtual
120 ~runtime_error() throw();
121
122 /** Returns a C-style character string describing the general cause of
123 * the current error (the same string passed to the ctor). */
124 virtual const char*
125 what() const throw();
126 };
127
128 /** Thrown to indicate range errors in internal computations. */
129 class range_error : public runtime_error
130 {
131 public:
132 explicit range_error(const string& __arg);
133 };
134
135 /** Thrown to indicate arithmetic overflow. */
136 class overflow_error : public runtime_error
137 {
138 public:
139 explicit overflow_error(const string& __arg);
140 };
141
142 /** Thrown to indicate arithmetic underflow. */
143 class underflow_error : public runtime_error
144 {
145 public:
146 explicit underflow_error(const string& __arg);
147 };
148
149 // @} group exceptions
150
151 _GLIBCXX_END_NAMESPACE_VERSION
152 } // namespace
153
154 #endif /* _GLIBCXX_STDEXCEPT */