]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/std/stdexcept
Makefile.am (std_headers): Remove cXXX from list.
[thirdparty/gcc.git] / libstdc++-v3 / include / std / stdexcept
CommitLineData
54c1bf78 1// Standard exception classes -*- C++ -*-
de96ac46
BK
2
3// Copyright (C) 2001 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 2, 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// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING. If not, write to the Free
18// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19// USA.
20
21// As a special exception, you may use this file as part of a free software
22// library without restriction. Specifically, if other files instantiate
23// templates or use macros or inline functions from this file, or you compile
24// this file and link it with other files to produce an executable, this
25// file does not by itself cause the resulting executable to be covered by
26// the GNU General Public License. This exception does not however
27// invalidate any other reasons why the executable file might be covered by
28// the GNU General Public License.
29
54c1bf78
BK
30//
31// ISO C++ 19.1 Exception classes
32//
33
34/** @file std_stdexcept.h
35 * The Standard C++ library provides classes to be used to report certain
36 * errors (17.4.4.8) in C++ programs. In the error model reflected in these
37 * classes, errors are divided into two broad categories: logic errors and
38 * runtime errors.
2f9d51b8
PE
39 */
40
725dc051 41#ifndef _CPP_STDEXCEPT
54c1bf78
BK
42#define _CPP_STDEXCEPT 1
43
44#pragma GCC system_header
45
46#include <exception>
47#include <string>
48
49namespace std
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 mathmatical 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} // namespace std
149
150#endif // _CPP_STDEXCEPT