libstdc++
stdexcept
Go to the documentation of this file.
00001 // Standard exception classes  -*- C++ -*-
00002 
00003 // Copyright (C) 2001, 2002, 2005, 2007, 2009, 2010, 2011
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the
00009 // Free Software Foundation; either version 3, or (at your option)
00010 // any later version.
00011 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // Under Section 7 of GPL version 3, you are granted additional
00018 // permissions described in the GCC Runtime Library Exception, version
00019 // 3.1, as published by the Free Software Foundation.
00020 
00021 // You should have received a copy of the GNU General Public License and
00022 // a copy of the GCC Runtime Library Exception along with this program;
00023 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00024 // <http://www.gnu.org/licenses/>.
00025 
00026 /** @file include/stdexcept
00027  *  This is a Standard C++ Library header.
00028  */
00029 
00030 //
00031 // ISO C++ 19.1  Exception classes
00032 //
00033 
00034 #ifndef _GLIBCXX_STDEXCEPT
00035 #define _GLIBCXX_STDEXCEPT 1
00036 
00037 #pragma GCC system_header
00038 
00039 #include <exception>
00040 #include <string>
00041 
00042 namespace std _GLIBCXX_VISIBILITY(default)
00043 {
00044 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00045 
00046   /**
00047    * @addtogroup exceptions
00048    * @{
00049    */
00050 
00051   /** Logic errors represent problems in the internal logic of a program;
00052    *  in theory, these are preventable, and even detectable before the
00053    *  program runs (e.g., violations of class invariants).
00054    *  @brief One of two subclasses of exception.
00055    */
00056   class logic_error : public exception 
00057   {
00058     string _M_msg;
00059 
00060   public:
00061     /** Takes a character string describing the error.  */
00062     explicit 
00063     logic_error(const string& __arg);
00064 
00065     virtual ~logic_error() _GLIBCXX_USE_NOEXCEPT;
00066 
00067     /** Returns a C-style character string describing the general cause of
00068      *  the current error (the same string passed to the ctor).  */
00069     virtual const char* 
00070     what() const _GLIBCXX_USE_NOEXCEPT;
00071   };
00072 
00073   /** Thrown by the library, or by you, to report domain errors (domain in
00074    *  the mathematical sense).  */
00075   class domain_error : public logic_error 
00076   {
00077   public:
00078     explicit domain_error(const string& __arg);
00079     virtual ~domain_error() _GLIBCXX_USE_NOEXCEPT;
00080   };
00081 
00082   /** Thrown to report invalid arguments to functions.  */
00083   class invalid_argument : public logic_error 
00084   {
00085   public:
00086     explicit invalid_argument(const string& __arg);
00087     virtual ~invalid_argument() _GLIBCXX_USE_NOEXCEPT;
00088   };
00089 
00090   /** Thrown when an object is constructed that would exceed its maximum
00091    *  permitted size (e.g., a basic_string instance).  */
00092   class length_error : public logic_error 
00093   {
00094   public:
00095     explicit length_error(const string& __arg);
00096     virtual ~length_error() _GLIBCXX_USE_NOEXCEPT;
00097   };
00098 
00099   /** This represents an argument whose value is not within the expected
00100    *  range (e.g., boundary checks in basic_string).  */
00101   class out_of_range : public logic_error 
00102   {
00103   public:
00104     explicit out_of_range(const string& __arg);
00105     virtual ~out_of_range() _GLIBCXX_USE_NOEXCEPT;
00106   };
00107 
00108   /** Runtime errors represent problems outside the scope of a program;
00109    *  they cannot be easily predicted and can generally only be caught as
00110    *  the program executes.
00111    *  @brief One of two subclasses of exception.
00112    */
00113   class runtime_error : public exception 
00114   {
00115     string _M_msg;
00116 
00117   public:
00118     /** Takes a character string describing the error.  */
00119     explicit 
00120     runtime_error(const string& __arg);
00121 
00122     virtual ~runtime_error() _GLIBCXX_USE_NOEXCEPT;
00123 
00124     /** Returns a C-style character string describing the general cause of
00125      *  the current error (the same string passed to the ctor).  */
00126     virtual const char* 
00127     what() const _GLIBCXX_USE_NOEXCEPT;
00128   };
00129 
00130   /** Thrown to indicate range errors in internal computations.  */
00131   class range_error : public runtime_error 
00132   {
00133   public:
00134     explicit range_error(const string& __arg);
00135     virtual ~range_error() _GLIBCXX_USE_NOEXCEPT;
00136   };
00137 
00138   /** Thrown to indicate arithmetic overflow.  */
00139   class overflow_error : public runtime_error 
00140   {
00141   public:
00142     explicit overflow_error(const string& __arg);
00143     virtual ~overflow_error() _GLIBCXX_USE_NOEXCEPT;
00144   };
00145 
00146   /** Thrown to indicate arithmetic underflow.  */
00147   class underflow_error : public runtime_error 
00148   {
00149   public:
00150     explicit underflow_error(const string& __arg);
00151     virtual ~underflow_error() _GLIBCXX_USE_NOEXCEPT;
00152   };
00153 
00154   // @} group exceptions
00155 
00156 _GLIBCXX_END_NAMESPACE_VERSION
00157 } // namespace
00158 
00159 #endif /* _GLIBCXX_STDEXCEPT */