00001 // Standard exception classes -*- C++ -*- 00002 00003 // Copyright (C) 2001, 2002, 2005 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 /** @file stdexcept 00031 * This is a Standard C++ Library header. 00032 */ 00033 00034 // 00035 // ISO C++ 19.1 Exception classes 00036 // 00037 00038 #ifndef _GLIBCXX_STDEXCEPT 00039 #define _GLIBCXX_STDEXCEPT 1 00040 00041 #pragma GCC system_header 00042 00043 #include <exception> 00044 #include <string> 00045 00046 _GLIBCXX_BEGIN_NAMESPACE(std) 00047 00048 /** Logic errors represent problems in the internal logic of a program; 00049 * in theory, these are preventable, and even detectable before the 00050 * program runs (e.g., violations of class invariants). 00051 * @brief One of two subclasses of exception. 00052 */ 00053 class logic_error : public exception 00054 { 00055 string _M_msg; 00056 00057 public: 00058 /** Takes a character string describing the error. */ 00059 explicit 00060 logic_error(const string& __arg); 00061 00062 virtual 00063 ~logic_error() throw(); 00064 00065 /** Returns a C-style character string describing the general cause of 00066 * the current error (the same string passed to the ctor). */ 00067 virtual const char* 00068 what() const throw(); 00069 }; 00070 00071 /** Thrown by the library, or by you, to report domain errors (domain in 00072 * the mathmatical sense). */ 00073 class domain_error : public logic_error 00074 { 00075 public: 00076 explicit domain_error(const string& __arg); 00077 }; 00078 00079 /** Thrown to report invalid arguments to functions. */ 00080 class invalid_argument : public logic_error 00081 { 00082 public: 00083 explicit invalid_argument(const string& __arg); 00084 }; 00085 00086 /** Thrown when an object is constructed that would exceed its maximum 00087 * permitted size (e.g., a basic_string instance). */ 00088 class length_error : public logic_error 00089 { 00090 public: 00091 explicit length_error(const string& __arg); 00092 }; 00093 00094 /** This represents an argument whose value is not within the expected 00095 * range (e.g., boundary checks in basic_string). */ 00096 class out_of_range : public logic_error 00097 { 00098 public: 00099 explicit out_of_range(const string& __arg); 00100 }; 00101 00102 /** Runtime errors represent problems outside the scope of a program; 00103 * they cannot be easily predicted and can generally only be caught as 00104 * the program executes. 00105 * @brief One of two subclasses of exception. 00106 */ 00107 class runtime_error : public exception 00108 { 00109 string _M_msg; 00110 00111 public: 00112 /** Takes a character string describing the error. */ 00113 explicit 00114 runtime_error(const string& __arg); 00115 00116 virtual 00117 ~runtime_error() throw(); 00118 00119 /** Returns a C-style character string describing the general cause of 00120 * the current error (the same string passed to the ctor). */ 00121 virtual const char* 00122 what() const throw(); 00123 }; 00124 00125 /** Thrown to indicate range errors in internal computations. */ 00126 class range_error : public runtime_error 00127 { 00128 public: 00129 explicit range_error(const string& __arg); 00130 }; 00131 00132 /** Thrown to indicate arithmetic overflow. */ 00133 class overflow_error : public runtime_error 00134 { 00135 public: 00136 explicit overflow_error(const string& __arg); 00137 }; 00138 00139 /** Thrown to indicate arithmetic underflow. */ 00140 class underflow_error : public runtime_error 00141 { 00142 public: 00143 explicit underflow_error(const string& __arg); 00144 }; 00145 00146 _GLIBCXX_END_NAMESPACE 00147 00148 #endif /* _GLIBCXX_STDEXCEPT */