# stdexcept

Go to the documentation of this file.

    00001 // Standard exception classes  -*- C++ -*-
    00002
    00003 // Copyright (C) 2001, 2002 Free Software Foundation, Inc.
    00004 //
    00005 // This file is part of the GNU ISO C++ Library.  This library is free
    00006 // software; you can redistribute it and/or modify it under the
    00007 // terms of the GNU General Public License as published by the
    00008 // Free Software Foundation; either version 2, or (at your option)
    00009 // any later version.
    00010
    00011 // This library is distributed in the hope that it will be useful,
    00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014 // GNU General Public License for more details.
    00015
    00016 // You should have received a copy of the GNU General Public License along
    00017 // with this library; see the file COPYING.  If not, write to the Free
    00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    00019 // USA.
    00020
    00021 // As a special exception, you may use this file as part of a free software
    00022 // library without restriction.  Specifically, if other files instantiate
    00023 // templates or use macros or inline functions from this file, or you compile
    00024 // this file and link it with other files to produce an executable, this
    00025 // file does not by itself cause the resulting executable to be covered by
    00026 // the GNU General Public License.  This exception does not however
    00027 // invalidate any other reasons why the executable file might be covered by
    00028 // the GNU General Public License.
    00029
    00030 //
    00031 // ISO C++ 19.1  Exception classes
    00032 //
    00033
    00034 /** @file stdexcept
    00035  *  This is a Standard C++ Library header.  You should @c #include this header
    00036  *  in your programs, rather than any of the "st[dl]_*.h" implementation files.
    00037  */
    00038
    00039 #ifndef _GLIBCXX_STDEXCEPT
    00040 #define _GLIBCXX_STDEXCEPT 1
    00041
    00042 #pragma GCC system_header
    00043
    00044 #include <exception>
    00045 #include <string>
    00046
    00047 namespace std
    00048 {
    00049   /** Logic errors represent problems in the internal logic of a program;
    00050    *  in theory, these are preventable, and even detectable before the
    00051    *  program runs (e.g., violations of class invariants).
    00052    *  @brief One of two subclasses of exception.
    00053    */
    00054   class logic_error : public exception
    00055   {
    00056     string _M_msg;
    00057
    00058   public:
    00059     /** Takes a character string describing the error.  */
    00060     explicit
    00061     logic_error(const string&  __arg);
    00062
    00063     virtual
    00064     ~logic_error() throw();
    00065
    00066     /** Returns a C-style character string describing the general cause of
    00067      *  the current error (the same string passed to the ctor).  */
    00068     virtual const char*
    00069     what() const throw();
    00070   };
    00071
    00072   /** Thrown by the library, or by you, to report domain errors (domain in
    00073    *  the mathmatical sense).  */
    00074   class domain_error : public logic_error
    00075   {
    00076   public:
    00077     explicit domain_error(const string&  __arg);
    00078   };
    00079
    00080   /** Thrown to report invalid arguments to functions.  */
    00081   class invalid_argument : public logic_error
    00082   {
    00083   public:
    00084     explicit invalid_argument(const string&  __arg);
    00085   };
    00086
    00087   /** Thrown when an object is constructed that would exceed its maximum
    00088    *  permitted size (e.g., a basic_string instance).  */
    00089   class length_error : public logic_error
    00090   {
    00091   public:
    00092     explicit length_error(const string&  __arg);
    00093   };
    00094
    00095   /** This represents an argument whose value is not within the expected
    00096    *  range (e.g., boundary checks in basic_string).  */
    00097   class out_of_range : public logic_error
    00098   {
    00099   public:
    00100     explicit out_of_range(const string&  __arg);
    00101   };
    00102
    00103   /** Runtime errors represent problems outside the scope of a program;
    00104    *  they cannot be easily predicted and can generally only be caught as
    00105    *  the program executes.
    00106    *  @brief One of two subclasses of exception.
    00107    */
    00108   class runtime_error : public exception
    00109   {
    00110     string _M_msg;
    00111
    00112   public:
    00113     /** Takes a character string describing the error.  */
    00114     explicit
    00115     runtime_error(const string&  __arg);
    00116
    00117     virtual
    00118     ~runtime_error() throw();
    00119
    00120     /** Returns a C-style character string describing the general cause of
    00121      *  the current error (the same string passed to the ctor).  */
    00122     virtual const char*
    00123     what() const throw();
    00124   };
    00125
    00126   /** Thrown to indicate range errors in internal computations.  */
    00127   class range_error : public runtime_error
    00128   {
    00129   public:
    00130     explicit range_error(const string&  __arg);
    00131   };
    00132
    00133   /** Thrown to indicate arithmetic overflow.  */
    00134   class overflow_error : public runtime_error
    00135   {
    00136   public:
    00137     explicit overflow_error(const string&  __arg);
    00138   };
    00139
    00140   /** Thrown to indicate arithmetic underflow.  */
    00141   class underflow_error : public runtime_error
    00142   {
    00143   public:
    00144     explicit underflow_error(const string&  __arg);
    00145   };
    00146 } // namespace std
    00147
    00148 #endif /* _GLIBCXX_STDEXCEPT */