Mark as release
[official-gcc.git] / libstdc++-v3 / include / std / std_stdexcept.h
blob2d56b3817d41664293a16f7f03dca68f3a84dd11
1 // Standard exception classes -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2005 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.
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.
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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
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.
30 /** @file stdexcept
31 * This is a Standard C++ Library header.
35 // ISO C++ 19.1 Exception classes
38 #ifndef _GLIBCXX_STDEXCEPT
39 #define _GLIBCXX_STDEXCEPT 1
41 #pragma GCC system_header
43 #include <exception>
44 #include <string>
46 _GLIBCXX_BEGIN_NAMESPACE(std)
48 /** Logic errors represent problems in the internal logic of a program;
49 * in theory, these are preventable, and even detectable before the
50 * program runs (e.g., violations of class invariants).
51 * @brief One of two subclasses of exception.
53 class logic_error : public exception
55 string _M_msg;
57 public:
58 /** Takes a character string describing the error. */
59 explicit
60 logic_error(const string& __arg);
62 virtual
63 ~logic_error() throw();
65 /** Returns a C-style character string describing the general cause of
66 * the current error (the same string passed to the ctor). */
67 virtual const char*
68 what() const throw();
71 /** Thrown by the library, or by you, to report domain errors (domain in
72 * the mathmatical sense). */
73 class domain_error : public logic_error
75 public:
76 explicit domain_error(const string& __arg);
79 /** Thrown to report invalid arguments to functions. */
80 class invalid_argument : public logic_error
82 public:
83 explicit invalid_argument(const string& __arg);
86 /** Thrown when an object is constructed that would exceed its maximum
87 * permitted size (e.g., a basic_string instance). */
88 class length_error : public logic_error
90 public:
91 explicit length_error(const string& __arg);
94 /** This represents an argument whose value is not within the expected
95 * range (e.g., boundary checks in basic_string). */
96 class out_of_range : public logic_error
98 public:
99 explicit out_of_range(const string& __arg);
102 /** Runtime errors represent problems outside the scope of a program;
103 * they cannot be easily predicted and can generally only be caught as
104 * the program executes.
105 * @brief One of two subclasses of exception.
107 class runtime_error : public exception
109 string _M_msg;
111 public:
112 /** Takes a character string describing the error. */
113 explicit
114 runtime_error(const string& __arg);
116 virtual
117 ~runtime_error() throw();
119 /** Returns a C-style character string describing the general cause of
120 * the current error (the same string passed to the ctor). */
121 virtual const char*
122 what() const throw();
125 /** Thrown to indicate range errors in internal computations. */
126 class range_error : public runtime_error
128 public:
129 explicit range_error(const string& __arg);
132 /** Thrown to indicate arithmetic overflow. */
133 class overflow_error : public runtime_error
135 public:
136 explicit overflow_error(const string& __arg);
139 /** Thrown to indicate arithmetic underflow. */
140 class underflow_error : public runtime_error
142 public:
143 explicit underflow_error(const string& __arg);
146 _GLIBCXX_END_NAMESPACE
148 #endif /* _GLIBCXX_STDEXCEPT */