xref: /dflybsd-src/contrib/gcc-4.7/libstdc++-v3/include/std/stdexcept (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino// Standard exception classes  -*- C++ -*-
2*e4b17023SJohn Marino
3*e4b17023SJohn Marino// Copyright (C) 2001, 2002, 2005, 2007, 2009, 2010, 2011
4*e4b17023SJohn Marino// Free Software Foundation, Inc.
5*e4b17023SJohn Marino//
6*e4b17023SJohn Marino// This file is part of the GNU ISO C++ Library.  This library is free
7*e4b17023SJohn Marino// software; you can redistribute it and/or modify it under the
8*e4b17023SJohn Marino// terms of the GNU General Public License as published by the
9*e4b17023SJohn Marino// Free Software Foundation; either version 3, or (at your option)
10*e4b17023SJohn Marino// any later version.
11*e4b17023SJohn Marino
12*e4b17023SJohn Marino// This library is distributed in the hope that it will be useful,
13*e4b17023SJohn Marino// but WITHOUT ANY WARRANTY; without even the implied warranty of
14*e4b17023SJohn Marino// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*e4b17023SJohn Marino// GNU General Public License for more details.
16*e4b17023SJohn Marino
17*e4b17023SJohn Marino// Under Section 7 of GPL version 3, you are granted additional
18*e4b17023SJohn Marino// permissions described in the GCC Runtime Library Exception, version
19*e4b17023SJohn Marino// 3.1, as published by the Free Software Foundation.
20*e4b17023SJohn Marino
21*e4b17023SJohn Marino// You should have received a copy of the GNU General Public License and
22*e4b17023SJohn Marino// a copy of the GCC Runtime Library Exception along with this program;
23*e4b17023SJohn Marino// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24*e4b17023SJohn Marino// <http://www.gnu.org/licenses/>.
25*e4b17023SJohn Marino
26*e4b17023SJohn Marino/** @file include/stdexcept
27*e4b17023SJohn Marino *  This is a Standard C++ Library header.
28*e4b17023SJohn Marino */
29*e4b17023SJohn Marino
30*e4b17023SJohn Marino//
31*e4b17023SJohn Marino// ISO C++ 19.1  Exception classes
32*e4b17023SJohn Marino//
33*e4b17023SJohn Marino
34*e4b17023SJohn Marino#ifndef _GLIBCXX_STDEXCEPT
35*e4b17023SJohn Marino#define _GLIBCXX_STDEXCEPT 1
36*e4b17023SJohn Marino
37*e4b17023SJohn Marino#pragma GCC system_header
38*e4b17023SJohn Marino
39*e4b17023SJohn Marino#include <exception>
40*e4b17023SJohn Marino#include <string>
41*e4b17023SJohn Marino
42*e4b17023SJohn Marinonamespace std _GLIBCXX_VISIBILITY(default)
43*e4b17023SJohn Marino{
44*e4b17023SJohn Marino_GLIBCXX_BEGIN_NAMESPACE_VERSION
45*e4b17023SJohn Marino
46*e4b17023SJohn Marino  /**
47*e4b17023SJohn Marino   * @addtogroup exceptions
48*e4b17023SJohn Marino   * @{
49*e4b17023SJohn Marino   */
50*e4b17023SJohn Marino
51*e4b17023SJohn Marino  /** Logic errors represent problems in the internal logic of a program;
52*e4b17023SJohn Marino   *  in theory, these are preventable, and even detectable before the
53*e4b17023SJohn Marino   *  program runs (e.g., violations of class invariants).
54*e4b17023SJohn Marino   *  @brief One of two subclasses of exception.
55*e4b17023SJohn Marino   */
56*e4b17023SJohn Marino  class logic_error : public exception
57*e4b17023SJohn Marino  {
58*e4b17023SJohn Marino    string _M_msg;
59*e4b17023SJohn Marino
60*e4b17023SJohn Marino  public:
61*e4b17023SJohn Marino    /** Takes a character string describing the error.  */
62*e4b17023SJohn Marino    explicit
63*e4b17023SJohn Marino    logic_error(const string& __arg);
64*e4b17023SJohn Marino
65*e4b17023SJohn Marino    virtual ~logic_error() _GLIBCXX_USE_NOEXCEPT;
66*e4b17023SJohn Marino
67*e4b17023SJohn Marino    /** Returns a C-style character string describing the general cause of
68*e4b17023SJohn Marino     *  the current error (the same string passed to the ctor).  */
69*e4b17023SJohn Marino    virtual const char*
70*e4b17023SJohn Marino    what() const _GLIBCXX_USE_NOEXCEPT;
71*e4b17023SJohn Marino  };
72*e4b17023SJohn Marino
73*e4b17023SJohn Marino  /** Thrown by the library, or by you, to report domain errors (domain in
74*e4b17023SJohn Marino   *  the mathematical sense).  */
75*e4b17023SJohn Marino  class domain_error : public logic_error
76*e4b17023SJohn Marino  {
77*e4b17023SJohn Marino  public:
78*e4b17023SJohn Marino    explicit domain_error(const string& __arg);
79*e4b17023SJohn Marino    virtual ~domain_error() _GLIBCXX_USE_NOEXCEPT;
80*e4b17023SJohn Marino  };
81*e4b17023SJohn Marino
82*e4b17023SJohn Marino  /** Thrown to report invalid arguments to functions.  */
83*e4b17023SJohn Marino  class invalid_argument : public logic_error
84*e4b17023SJohn Marino  {
85*e4b17023SJohn Marino  public:
86*e4b17023SJohn Marino    explicit invalid_argument(const string& __arg);
87*e4b17023SJohn Marino    virtual ~invalid_argument() _GLIBCXX_USE_NOEXCEPT;
88*e4b17023SJohn Marino  };
89*e4b17023SJohn Marino
90*e4b17023SJohn Marino  /** Thrown when an object is constructed that would exceed its maximum
91*e4b17023SJohn Marino   *  permitted size (e.g., a basic_string instance).  */
92*e4b17023SJohn Marino  class length_error : public logic_error
93*e4b17023SJohn Marino  {
94*e4b17023SJohn Marino  public:
95*e4b17023SJohn Marino    explicit length_error(const string& __arg);
96*e4b17023SJohn Marino    virtual ~length_error() _GLIBCXX_USE_NOEXCEPT;
97*e4b17023SJohn Marino  };
98*e4b17023SJohn Marino
99*e4b17023SJohn Marino  /** This represents an argument whose value is not within the expected
100*e4b17023SJohn Marino   *  range (e.g., boundary checks in basic_string).  */
101*e4b17023SJohn Marino  class out_of_range : public logic_error
102*e4b17023SJohn Marino  {
103*e4b17023SJohn Marino  public:
104*e4b17023SJohn Marino    explicit out_of_range(const string& __arg);
105*e4b17023SJohn Marino    virtual ~out_of_range() _GLIBCXX_USE_NOEXCEPT;
106*e4b17023SJohn Marino  };
107*e4b17023SJohn Marino
108*e4b17023SJohn Marino  /** Runtime errors represent problems outside the scope of a program;
109*e4b17023SJohn Marino   *  they cannot be easily predicted and can generally only be caught as
110*e4b17023SJohn Marino   *  the program executes.
111*e4b17023SJohn Marino   *  @brief One of two subclasses of exception.
112*e4b17023SJohn Marino   */
113*e4b17023SJohn Marino  class runtime_error : public exception
114*e4b17023SJohn Marino  {
115*e4b17023SJohn Marino    string _M_msg;
116*e4b17023SJohn Marino
117*e4b17023SJohn Marino  public:
118*e4b17023SJohn Marino    /** Takes a character string describing the error.  */
119*e4b17023SJohn Marino    explicit
120*e4b17023SJohn Marino    runtime_error(const string& __arg);
121*e4b17023SJohn Marino
122*e4b17023SJohn Marino    virtual ~runtime_error() _GLIBCXX_USE_NOEXCEPT;
123*e4b17023SJohn Marino
124*e4b17023SJohn Marino    /** Returns a C-style character string describing the general cause of
125*e4b17023SJohn Marino     *  the current error (the same string passed to the ctor).  */
126*e4b17023SJohn Marino    virtual const char*
127*e4b17023SJohn Marino    what() const _GLIBCXX_USE_NOEXCEPT;
128*e4b17023SJohn Marino  };
129*e4b17023SJohn Marino
130*e4b17023SJohn Marino  /** Thrown to indicate range errors in internal computations.  */
131*e4b17023SJohn Marino  class range_error : public runtime_error
132*e4b17023SJohn Marino  {
133*e4b17023SJohn Marino  public:
134*e4b17023SJohn Marino    explicit range_error(const string& __arg);
135*e4b17023SJohn Marino    virtual ~range_error() _GLIBCXX_USE_NOEXCEPT;
136*e4b17023SJohn Marino  };
137*e4b17023SJohn Marino
138*e4b17023SJohn Marino  /** Thrown to indicate arithmetic overflow.  */
139*e4b17023SJohn Marino  class overflow_error : public runtime_error
140*e4b17023SJohn Marino  {
141*e4b17023SJohn Marino  public:
142*e4b17023SJohn Marino    explicit overflow_error(const string& __arg);
143*e4b17023SJohn Marino    virtual ~overflow_error() _GLIBCXX_USE_NOEXCEPT;
144*e4b17023SJohn Marino  };
145*e4b17023SJohn Marino
146*e4b17023SJohn Marino  /** Thrown to indicate arithmetic underflow.  */
147*e4b17023SJohn Marino  class underflow_error : public runtime_error
148*e4b17023SJohn Marino  {
149*e4b17023SJohn Marino  public:
150*e4b17023SJohn Marino    explicit underflow_error(const string& __arg);
151*e4b17023SJohn Marino    virtual ~underflow_error() _GLIBCXX_USE_NOEXCEPT;
152*e4b17023SJohn Marino  };
153*e4b17023SJohn Marino
154*e4b17023SJohn Marino  // @} group exceptions
155*e4b17023SJohn Marino
156*e4b17023SJohn Marino_GLIBCXX_END_NAMESPACE_VERSION
157*e4b17023SJohn Marino} // namespace
158*e4b17023SJohn Marino
159*e4b17023SJohn Marino#endif /* _GLIBCXX_STDEXCEPT */
160