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