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