libstdc++: stdexcept Source File

libstdc++

stdexcept
Go to the documentation of this file.
1// Standard exception classes -*- 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 include/stdexcept
26 * This is a Standard C++ Library header.
27 */
28
29//
30// ISO C++ 19.1 Exception classes
31//
32
33#ifndef _GLIBCXX_STDEXCEPT
34#define _GLIBCXX_STDEXCEPT 1
35
36#ifdef _GLIBCXX_SYSHDR
37#pragma GCC system_header
38#endif
39
40#include <exception>
41#include <string>
42#include <bits/stdexcept_except.h>
43
44namespace std _GLIBCXX_VISIBILITY(default)
45{
46_GLIBCXX_BEGIN_NAMESPACE_VERSION
47
48 /**
49 * @addtogroup exceptions
50 * @{
51 */
52
53 /** Thrown to indicate range errors in internal computations. */
54 class range_error : public runtime_error
55 {
56 public:
57#if __cpp_lib_constexpr_exceptions >= 202502L
58 constexpr explicit range_error(const string& __arg) _GLIBCXX_TXN_SAFE
59 : runtime_error(__arg) { }
60 constexpr explicit range_error(const char* __arg) _GLIBCXX_TXN_SAFE
61 : runtime_error(__arg) { }
62 constexpr range_error(const range_error&) = default;
63 constexpr range_error& operator=(const range_error&) = default;
64 constexpr range_error(range_error&&) = default;
65 constexpr range_error& operator=(range_error&&) = default;
66 constexpr virtual ~range_error() noexcept { }
67#else
68 explicit range_error(const string& __arg) _GLIBCXX_TXN_SAFE;
69#if __cplusplus >= 201103L
70 explicit range_error(const char*) _GLIBCXX_TXN_SAFE;
71 range_error(const range_error&) = default;
72 range_error& operator=(const range_error&) = default;
73 range_error(range_error&&) = default;
74 range_error& operator=(range_error&&) = default;
75#endif
76 virtual ~range_error() _GLIBCXX_NOTHROW;
77#endif
78 };
79
80 /// @} group exceptions
81
82_GLIBCXX_END_NAMESPACE_VERSION
83} // namespace
84
85#endif /* _GLIBCXX_STDEXCEPT */
exception
string
stdexcept_except.h
std
ISO C++ entities toplevel namespace is std.
std::runtime_error::runtime_error
runtime_error(const string &__arg)