libstdc++: stdexcept_throwdef.h Source File

libstdc++

stdexcept_throwdef.h
Go to the documentation of this file.
1// Function-Based Exception Support -*- C++ -*-
2
3// Copyright (C) 2001-2026 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/** @file bits/stdexcept_throwdef.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{stdexcept}
28 */
29
30//
31// ISO C++ 14882: 19.1 Exception classes
32//
33
34#ifndef _STDEXCEPT_THROWDEF_H
35#define _STDEXCEPT_THROWDEF_H 1
36
37#include <bits/c++config.h>
38#include <bits/exception_defines.h>
39#if (_GLIBCXX_HOSTED && __cpp_exceptions && __cplusplus > 202302L \
40 && __cpp_constexpr_exceptions >= 202411L)
41
42namespace std _GLIBCXX_VISIBILITY(default)
43{
44_GLIBCXX_BEGIN_NAMESPACE_VERSION
45
46 // Helpers for exception objects in <stdexcept>
47 namespace __detail
48 {
49 extern "C"
50 {
51 [[noreturn, __gnu__::__cold__]] void
52 _ZSt19__throw_logic_errorPKc(const char*);
53
54 [[noreturn, __gnu__::__cold__]] void
55 _ZSt20__throw_domain_errorPKc(const char*);
56
57 [[noreturn, __gnu__::__cold__]] void
58 _ZSt24__throw_invalid_argumentPKc(const char*);
59
60 [[noreturn, __gnu__::__cold__]] void
61 _ZSt20__throw_length_errorPKc(const char*);
62
63 [[noreturn, __gnu__::__cold__]] void
64 _ZSt20__throw_out_of_rangePKc(const char*);
65
66 [[noreturn, __gnu__::__cold__]]
67 [[__gnu__::__format__(__gnu_printf__, 1, 2)]] void
68 _ZSt24__throw_out_of_range_fmtPKcz(const char*, ...);
69
70 [[noreturn, __gnu__::__cold__]] void
71 _ZSt21__throw_runtime_errorPKc(const char*);
72
73 [[noreturn, __gnu__::__cold__]] void
74 _ZSt22__throw_overflow_errorPKc(const char*);
75
76 [[noreturn, __gnu__::__cold__]] void
77 _ZSt23__throw_underflow_errorPKc(const char*);
78 }
79 } // namespace __detail
80
81 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
82 __throw_logic_error(const char* __s)
83 {
84 if consteval {
85 throw logic_error(__s);
86 } else {
87 __detail::_ZSt19__throw_logic_errorPKc(__s);
88 }
89 }
90
91 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
92 __throw_domain_error(const char* __s)
93 {
94 if consteval {
95 throw domain_error(__s);
96 } else {
97 __detail::_ZSt20__throw_domain_errorPKc(__s);
98 }
99 }
100
101 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
102 __throw_invalid_argument(const char* __s)
103 {
104 if consteval {
105 throw invalid_argument(__s);
106 } else {
107 __detail::_ZSt24__throw_invalid_argumentPKc(__s);
108 }
109 }
110
111 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
112 __throw_length_error(const char* __s)
113 {
114 if consteval {
115 throw length_error(__s);
116 } else {
117 __detail::_ZSt20__throw_length_errorPKc(__s);
118 }
119 }
120
121 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
122 __throw_out_of_range(const char* __s)
123 {
124 if consteval {
125 throw out_of_range(__s);
126 } else {
127 __detail::_ZSt20__throw_out_of_rangePKc(__s);
128 }
129 }
130
131 template <typename... _Args>
132 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
133 __throw_out_of_range_fmt(const char* __s, _Args... __args)
134 {
135 if consteval {
136 throw out_of_range(__s);
137 } else {
138 __detail::_ZSt24__throw_out_of_range_fmtPKcz(__s, __args...);
139 }
140 }
141
142 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
143 __throw_runtime_error(const char* __s)
144 {
145 if consteval {
146 throw runtime_error(__s);
147 } else {
148 __detail::_ZSt21__throw_runtime_errorPKc(__s);
149 }
150 }
151
152 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
153 __throw_overflow_error(const char* __s)
154 {
155 if consteval {
156 throw overflow_error(__s);
157 } else {
158 __detail::_ZSt22__throw_overflow_errorPKc(__s);
159 }
160 }
161
162 [[noreturn, __gnu__::__always_inline__, __gnu__::__cold__]] constexpr void
163 __throw_underflow_error(const char* __s)
164 {
165 if consteval {
166 throw underflow_error(__s);
167 } else {
168 __detail::_ZSt23__throw_underflow_errorPKc(__s);
169 }
170 }
171
172_GLIBCXX_END_NAMESPACE_VERSION
173} // namespace
174
175#endif
176
177#endif
exception_defines.h
c++config.h
std
ISO C++ entities toplevel namespace is std.
std::__detail
Implementation details not part of the namespace std interface.
std::logic_error
One of two subclasses of exception.
Definition stdexcept_except.h:256
std::domain_error
Definition stdexcept_except.h:323
std::invalid_argument
Definition stdexcept_except.h:354
std::length_error
Definition stdexcept_except.h:387
std::out_of_range
Definition stdexcept_except.h:419
std::runtime_error
One of two subclasses of exception.
Definition stdexcept_except.h:454
std::overflow_error
Definition stdexcept_except.h:521
std::underflow_error
Definition stdexcept_except.h:553